[Solved] Display something only if page alias LIKE ?

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
xmas3
Forum Members
Forum Members
Posts: 41
Joined: Sat Jul 28, 2007 9:22 am
Location: Bratislava / Slovakia

[Solved] Display something only if page alias LIKE ?

Post by xmas3 »

Hi all,
Im trying to write a condition, that shows something (menu, text) only if page-alias contains some text/preffix.
Something similar as you can use in sqls  LIKE '%bob%' .

Is it possible to do it with smarty?

I tryied

Code: Select all

{if $page_alias == "text%"} 
in my page template but doesnt work.

Any suggestions?
Thanks a lot,Miro
Last edited by xmas3 on Tue Oct 28, 2008 12:02 pm, edited 1 time in total.
alby

Re: Display something only if page alias LIKE ?

Post by alby »

xmas3 wrote: Im trying to write a condition, that shows something (menu, text) only if page-alias contains some text/preffix.
Something similar as you can use in sqls  LIKE '%bob%' .
In MenuManager you can use include/exclude extension

Alby
xmas3
Forum Members
Forum Members
Posts: 41
Joined: Sat Jul 28, 2007 9:22 am
Location: Bratislava / Slovakia

Re: Display something only if page alias LIKE ?

Post by xmas3 »

Yes, of course, but what if I would like show other components (static text, banners etc.) only on selected pages having some predefined text in page-alias? Hmm?
M.
alby

Re: Display something only if page alias LIKE ?

Post by alby »

xmas3 wrote: Yes, of course, but what if I would like show other components (static text, banners etc.) only on selected pages having some predefined text in page-alias? Hmm?
No, for this you must change module sql code for = to LIKE behaviour

Alby
xmas3
Forum Members
Forum Members
Posts: 41
Joined: Sat Jul 28, 2007 9:22 am
Location: Bratislava / Slovakia

Re: Display something only if page alias LIKE ?

Post by xmas3 »

Im not sure what you are talking about...
Where should I change it?
M.
nhaack

Re: Display something only if page alias LIKE ?

Post by nhaack »

You could do it with smarty though.  :)

Code: Select all


   {if $page_alias|truncate:5:"" == "show_"}
      ...
        MY CODE
      ...
   {/if}

What this code will do in your template is the following: It will limit the alias to the first 5 characters. If our alias is "articlename", the variable will contain: "artic". If our alias has a prefix like "show_articlename", the variable will contain "show_". It then compares these first characters of the alias string with a defined string. If that is equal it does something.

If you want to use another prefix, state the character length behind truncate and state the desired prefix where you read "show_".


Hope this could solve your issue...

Best
Nils
Last edited by nhaack on Tue Oct 28, 2008 11:48 am, edited 1 time in total.
xmas3
Forum Members
Forum Members
Posts: 41
Joined: Sat Jul 28, 2007 9:22 am
Location: Bratislava / Slovakia

Re: Display something only if page alias LIKE ?

Post by xmas3 »

Great, thats what Ive been looking for.
Thanks a lot.
M.
Post Reply

Return to “Developers Discussion”