Add parameter to link in typoscript

12,234

Solution 1

First off, I don't think that the cobj text has a method data hence I would change that to the value method. Also when you want to use the getText data type you need to warp the variables with curly braces and then add the method insertData = 1 to it so everything inside the curly braces get replaced. Here is a complete example: http://wiki.typo3.org/TSref/getText. Of course you can use a typolink cobject to replace the page id. Second you can add an additional link parameter (i.e. get-parameters) with the additionalParams method (with a typolink of course) or you can use a plain cobj text. Here is an example with a cObj image and stdWrap cObj typolink and tt_news get-parameters. It also opens a popup-window.

             40=IMAGE
             40.file=print.gif                 
             40.stdWrap.wrap = <div>|</div>
             40.stdWrap.typolink.no_cache = 1 
             40.stdWrap.typolink.parameter.data = page:uid
             40.stdWrap.typolink.parameter.wrap = | ,1 print
             40.stdWrap.typolink.additionalParams.cObject = COA
             40.stdWrap.typolink.additionalParams.cObject {

                  10 = TEXT
                  10.data = GPvar : no_cache 
                  10.wrap = &no_cache=|
                  10.required = 1

                  20 = TEXT
                  20.data = GPvar : L
                  20.wrap = &L=|
                  20.required = 1

                  30 = TEXT
                  30.data = GPvar : backPID
                  30.wrap = &backPID=|
                  30.required = 1

                  40 = TEXT
                  40.data = GPvar : tt_news
                  40.wrap = &tt_news=|
                  40.required = 1

              }

Solution 2

According to typolink reference you need to use additionalParams

lib.myLink = TEXT
lib.mylink.value = Click me!
lib.mylink.typolink.parameter.data = page:uid
lib.mylink.typolink.additionalParams = &mainsite=1
lib.mylink.typolink.useCacheHash = 1

Keep in mind that each (even first) parameter in additionalParams begins with &. Most probably you'll need also make sure that it will generate cHash for proper caching.

Share:
12,234
ak85
Author by

ak85

mainly a frontend developer trying to learn more about php and mysql SOreadytohelp

Updated on July 31, 2022

Comments

  • ak85
    ak85 almost 2 years

    I have my site setup so that if you are on a mobile you get a mobile rendered template. To click to go to the main site you go

    index.php?id=??&mainsite=1
    

    This all works fine however I have a link at the bottom of my mobile template that says go to main site. I want this to go to the main template page for the current page id eg

    index.php?id=page:uid&mainsite=1
    

    If I do

    lib.mainsitelink= TEXT
    lib.mainsitelink.data = page:uid
    

    I get

    www.example.com/uid
    

    so when uid = 3 i get

    www.example.com/3
    

    but if i do the below code it doesn't work

    lib.mainsitelink= TEXT
    lib.mainsitelink.data = index.php?id=page:uid&mainsite=1
    

    Is there a way to either do what I am trying to do or add a parameter to the end of the current url? eg what I am trying to do won't quite work on the news single page.

  • Micromega
    Micromega almost 12 years
    This doesn't explain the use of gettext object but only explain additionalparams.
  • biesior
    biesior almost 12 years
    @Chiyou Yes, isn't it what he was asking about ? (additional params?) Again you're trying to prove thas OP was asking for something else, than he wrote in his question. there are thousand of possibilites and writing thousand of samples is not my job, as there're thousands of samples in the net.
  • Micromega
    Micromega almost 12 years
    No. It's just not a complete answer to solve his problem. I hope you can understand critics and btw. I see your score is high. That's not meant negative but you can improve you answer.
  • ak85
    ak85 almost 12 years
    as I noted in my question this won't work for the news single page.
  • Micromega
    Micromega almost 12 years
    I posted some code I didn't test it with single page. Maybe it's because you use no_cache get parameter disabled?
  • maholtz
    maholtz almost 12 years
    TEXT has a data property; be careful with tt_news backPID,; you should not add no_cache to an url if you can avoid; L-parameter should be added via config.linkVars; you cannot pass the cHash because it is computed. adding an wrong cHash just deactivates the cache; there is no stdWrap property "typolinkno_cache"
  • tmt
    tmt over 11 years
    I would say this almost is complete answer and it's how the link is supposed to be created. The only thing it's IMHO missing is lib.mylink.typolink.addQueryString = 1 so that other existing GET parameteres (e.g. UID of a news record) are added to the link.