Page 1 of 1
Use smarty var in item url
Posted: Thu Feb 26, 2015 9:23 am
by jack4ya
Hi in a module (ListIt2) in the detail template I know have:
Code: Select all
<a href="{$item->url|replace:'.com':'.com/en'}">
{if $display_language == 'de'}Weiter lesen
{elseif $display_language=='fr'}En savoir plus{/if}
{else}Read more{/if}
</a>
I also have a custom field called 'display_languange' (which is required to fill) in the module (not page/template level) so I have a param/field: $display_languange.
I would like to use that so I only need one template instead of multiple per language. (and I could use it for any module/lang)
So something like (bit both don't work)
Code: Select all
{$item->url|replace:'.com':'.com/$display_languange'}
{$item->url|replace:'.com':'.com/`$display_languange`'}
Or eval... capture... whatever. I tried enough now.

Any help?
Re: Use smarty var in item url
Posted: Thu Feb 26, 2015 9:41 am
by Rolf
languange >> language
Re: Use smarty var in item url
Posted: Thu Feb 26, 2015 9:50 am
by jack4ya
@rolf??
Added info: But I think it just might complicate the matter:
It's a multi lang setup like yours/Gorans with a 'page_lang' param... Site is setup with sectionheaders and I needed the Listit2 module links prefixed with the lang param as well. But it can't read that from page/template level so I added a new field/param/value to Lisitit2 modules also, and *that* value is the one I'm using in ListIt2 links.
I reoconstructed the url... I still need to manually alter my hardcoded domain address but its better than several templates per languange
<a href="{$display_language}/{$item->url|replace:'
http://www.domain.com/':''}">link</a>
Re: Use smarty var in item url
Posted: Thu Feb 26, 2015 12:33 pm
by velden
Smarty variables in CMSMS have a global scope usually meaning they should be available in all template IF the variable exists when processing the template.
No need to hard code the domain name. Example below generates absolute url:
Code: Select all
{$display_language='/'|cat:'nl'}
{root_url assign='rooturl'}
{foreach...}
<a href="{$item->url|replace:$rooturl:($rooturl|cat:$display_language)}">link</a>
{/foreach}
The 'nl' part could be replaced for a smarty variable if it does exist.
Re: Use smarty var in item url
Posted: Thu Feb 26, 2015 8:17 pm
by jack4ya
Ah, I guess a missed a bit of the newer/unfamiliar tags.
Time to freshen up! Thnx!
Re: Use smarty var in item url
Posted: Fri Feb 27, 2015 11:31 am
by jack4ya
Sorry can;t get it to work with the cat part.
{capture assign='root_url'}{root_url}{/capture}
{$display_language='/'|cat:'nl'} <--- ? what is this for?
{$display_language} will have one of these values 'en','fr','de'.
So I don't want/need to set it with another value.
I don't use categories at all, but I think you mean because it can be used to construct the url?
<a href="{$item->url|'replace:$root_url':'$root_url/$display_language'}">link</a> <-- DOnt know.
Re: Use smarty var in item url
Posted: Fri Feb 27, 2015 12:11 pm
by velden
Nothing to do with categories, but
concatenate.
I think this is more efficient though:
Code: Select all
{*get site's root url*}
{root_url assign='rooturl'}
{*get language part for url
this should come from mle module/method actually *}
{$display_language='nl'}
{*generate new root_url with language part*}
{$new_rooturl="$rooturl/$display_language"}
{foreach ...}
{$item->url|replace:$rooturl:$new_rooturl}
{/foreach}
I try to get as much as possible outside the foreach loop for obvious reasons (efficiency).
Re: Use smarty var in item url
Posted: Fri Feb 27, 2015 8:42 pm
by jack4ya
I literally reused your code... I already had an root_url defined... but apparent something faulty... so I assign another one.