Fork me on GitHub

tip: concatenate parameters with smarty  Bottom

  • if you want to pass parameters to a Smarty, you can use the cat modifier

    You can use it like that

    Code

    <!--[ pnmodurl modname=pnForum type=user func=main fragment=$forum.cat_id|cat:"cat" ]-->">


    in order to have the following ouput

    Code

    index.php?module=pnForum#2cat


    AND you can use it like that

    Code

    <!--[ pnmodurl modname=pnForum type=user func=main fragment="cat"|cat:$forum.cat_id ]-->">


    in order to have the following ouput

    Code

    index.php?module=pnForum#cat2


    http://www.smarty.net/manual/en/language.modifier.cat.php
  • There is also the assign_concat pnRender plugin which allows you to concatenate up to 10 arguments and assign the result to a new variable.

    Greetings
    R
  • Yeah, you can do nice stuff with the modifiers:
    the page with all of them: http://www.smarty.ne…guage.modifiers.php
    Also multiple cats after each other:

    Code

    <!--[pnpageaddvar name="rawtext" value='<style type="text/css">'|cat:$parsedstyle|cat:'</style>']-->

    or an inline string replacement

    Code

    <!--[pnml name=$scrollstyle|replace:'%DIVID%':$divid assign=parsedstyle]-->




    --
    campertoday.nl, Module development, Dutch Zikula Community
  • the idea was to avoid two lines of code in the template,

    but assign_concat is more fit if you ve got multiple arguments



    edited by: mumuri, Apr 06, 2008 - 03:43 AM
  • Another interesting use is for the adding an IE conditional statement with pnpageaddvar. For example

    Code

    <!--[pnpageaddvar name='rawtext' value=$smarty.ldelim|cat:'if lte IE 7]><somejsscriptcall...><![endif'|cat:$smarty.rdelim]-->

    this gives in the template:

    Code

    <!--[if lte IE 7]><somejsscriptcall...><![endif]-->

    I replaced the actual script call, since that is skipped in the forum entry anyway icon_smile



    edited by: espaan, datetimebrief

    --
    campertoday.nl, Module development, Dutch Zikula Community
  • i didn't know the use of $smarty.ldelim nice, was using litteral tags to avoid problem with that
  • I was using literal tags too icon_smile but remembered that I used this smarty.delim before and looked up how to do it again. Using literal made the script call end up somewhere in the page body (for a news module template) and in this way they end up nicely in the header.


    edit: BTW for those wondering why I update this old post icon_wink It is linked from the knowledgebase docs.



    edited by: espaan, datetimebrief

    --
    campertoday.nl, Module development, Dutch Zikula Community
  • 0 users

This list is based on users active over the last 60 minutes.