Smarty - what is it?
Smarty - what is it?
Hi, this may sound like a very rudimentary quesntion, but I cannot figure our what the smarty is, and how is it implemented in CMSMS. For an example, here is the how to use instruction for Custom Content module:
{if $customcontent_loggedin > 0}
Welcome {$customcontent_loginname}
{else}
You are not authorized to view this data
{/if}
Or you can use the $ccuser variable for more advanced, and easier to read testing
{if $ccuser->loggedin() && $ccuser->memberof('members') && $ccuser->ipmatches('192.168.0.0/24')}
Welcome logged in local member
{elseif $ccuser->loggedin() && $ccuser->memberof('members')}
Welcome logged in member
{elseif $ccuser->loggedin()}
Welcome user from some other group
{else}
Anonymous user
{/if}
{if $customcontent_loggedin > 0}
Welcome {$customcontent_loginname}
{else}
You are not authorized to view this data
{/if}
Or you can use the $ccuser variable for more advanced, and easier to read testing
{if $ccuser->loggedin() && $ccuser->memberof('members') && $ccuser->ipmatches('192.168.0.0/24')}
Welcome logged in local member
{elseif $ccuser->loggedin() && $ccuser->memberof('members')}
Welcome logged in member
{elseif $ccuser->loggedin()}
Welcome user from some other group
{else}
Anonymous user
{/if}
Re: Smarty - what is it?
Smarty is the template engine for CMSms http://www.smarty.net/manual/en/
You can customize the cms-output with it.
You seem to want to use the Custom Content module for something. Tell us what you are trying to achieve and we'll help you with it.
You can customize the cms-output with it.
You seem to want to use the Custom Content module for something. Tell us what you are trying to achieve and we'll help you with it.
Re: Smarty - what is it?
Thanks. What I intend to do is simple at this point:Jos wrote: Smarty is the template engine for CMSms http://www.smarty.net/manual/en/
You can customize the cms-output with it.
You seem to want to use the Custom Content module for something. Tell us what you are trying to achieve and we'll help you with it.
1. I want to create pages that I would like to show only to registered frontend users.
2. I may want to do a twist: to show them only to a group of frontend users.
But I would of courxe want to understand:
1. how to use the smarty codes given as examples with a number of modules of CMSMS (I tend to think they are used similar to {tags}, that is embeded into contents, but I failed trying.
Thanks so much for your help
Re: Smarty - what is it?
To begin with your last question:
With smarty you can put dynamic content in a static template. For normal pages, you may have seen the {content} tag or the {title} tag. They will be replaced with values that you have put in the pages fields. Also modules can have such tags, but they are only usable in module-templates.
There are also smarty functions like {if} and {foreach}
If you see a $-sign in those tags, they represent variables.
So for showing content only to authorised users, you provided the code allready:
{if $ccuser->loggedin() && $ccuser->memberof('members')}
Show your content here with {content} if you use this code in a template.
{else}
Message: Please login to access the requested information
{/if}
the variable $ccuser->loggedin() is set to true if the user is logged in.
the variable $ccuser->memberof('members') is set to true if the user is a member of the group named members.
There's a && between them, so both variables have to be true to output the content.
With smarty you can put dynamic content in a static template. For normal pages, you may have seen the {content} tag or the {title} tag. They will be replaced with values that you have put in the pages fields. Also modules can have such tags, but they are only usable in module-templates.
There are also smarty functions like {if} and {foreach}
If you see a $-sign in those tags, they represent variables.
So for showing content only to authorised users, you provided the code allready:
{if $ccuser->loggedin() && $ccuser->memberof('members')}
Show your content here with {content} if you use this code in a template.
{else}
Message: Please login to access the requested information
{/if}
the variable $ccuser->loggedin() is set to true if the user is logged in.
the variable $ccuser->memberof('members') is set to true if the user is a member of the group named members.
There's a && between them, so both variables have to be true to output the content.
Re: Smarty - what is it?
Thank for your reply.
I have tried entering the smarty code (shown above) into a content page. It did not work, because it was rendered as content. Obviously this is not the way to do.
I begin to realize that it need to be entered into a template replacing the {content} tag?
If so, where would the regular content be shown. Also, how can one assign pages to be shown to registered users WITHOUT putting the code of the content into the template.
As you may see, I am missing still out on the practicalities (were to put the code, where the constent, and so forth).
I have tried entering the smarty code (shown above) into a content page. It did not work, because it was rendered as content. Obviously this is not the way to do.
I begin to realize that it need to be entered into a template replacing the {content} tag?
If so, where would the regular content be shown. Also, how can one assign pages to be shown to registered users WITHOUT putting the code of the content into the template.
As you may see, I am missing still out on the practicalities (were to put the code, where the constent, and so forth).
Re: Smarty - what is it?
- Turn "WYSIWYG" editor off.
- In page options uncheck "Cachable:"
- Don't skip http://wiki.cmsmadesimple.org/index.php/User_Handbook and http://www.smarty.net/manual/en/
Re: Smarty - what is it?
correct. It's possible to put the code in the content-field of a page, but that is more complicated I think.docman wrote: I begin to realize that it need to be entered into a template replacing the {content} tag?
It's the most simple to have two templates, one for normal content and one for logged in users. When you create a page, you can choose the template you want for that page.docman wrote: If so, where would the regular content be shown. Also, how can one assign pages to be shown to registered users WITHOUT putting the code of the content into the template.
Re: Smarty - what is it?
Thanks. I am getting the idea.
Soon I test it.
Soon I test it.
Re: Smarty - what is it?
I did test it. I created a page with a template for the registeres users where I replaced the {content} tag by the thisdocman wrote: Thanks. I am getting the idea.
Soon I test it.
{if $customcontent_loggedin > 0}
Welcome {$customcontent_loginname}
{else}
You are not authorized to view this data
{/if}
I logged in and went to the page for the registered content. Instead of showing its content, the alert message was shown indicating that I am not logged in. I went back and checked if I remained logged in. Yes I did remained logged in.
I did investigate a bit further.
I found out that when I first visit the registered page after having goten logged in, instead os showing the content I placed in the body text, it greets me as a logged in visitor. However, if I insert content into the Intro Window, that is correctly shown.
Now if I leave this page and later return to it, (although still being logged in) it displays the error message (from the template tag) that I am not authorized to view this data.
[Still, later] Herueka!
I discovered that this code worked:
{if $ccuser->loggedin() && $ccuser->memberof('members') && $ccuser->ipmatches('192.168.0.0/24')}
Welcome logged in local member
{elseif $ccuser->loggedin() && $ccuser->memberof('members')}
{content}
{elseif $ccuser->loggedin()}
{content}
{else}
Anonymous user
{/if}
By the way: can a menu item be shown only to registered users?
Last edited by docman on Fri Oct 16, 2009 12:11 am, edited 1 time in total.
Re: Smarty - what is it?
yes, you found (as others have mentioned elsewhere) that the $customcontent_loginname syntax is deprecated. Hopefully Calguy will remove it from the Help file in an upcoming release, as it does cause confusion.docman wrote: I discovered that this code worked:
{if $ccuser->loggedin() && $ccuser->memberof('members') && $ccuser->ipmatches('192.168.0.0/24')}
Welcome logged in local member
{elseif $ccuser->loggedin() && $ccuser->memberof('members')}
{content}
{elseif $ccuser->loggedin()}
{content}
{else}
Anonymous user
{/if}
yesdocman wrote: By the way: can a menu item be shown only to registered users?
Re: Smarty - what is it?
Can you give me an example how can one hide/show menu items to FEUs? It would be a great help for me now.
Thanks in advance.
Thanks in advance.
Re: Smarty - what is it?
Also, apart from the deprecated code: you must have at least the {content} tag in your template, otherwise you cannot edit the content of pages and you will get problems with modules.docman wrote: I replaced the {content} tag by the this
{if $customcontent_loggedin > 0}
Welcome {$customcontent_loginname}
{else}
You are not authorized to view this data
{/if}
For the menu I used an extra {menu} tag with a startlevel and other parameters (look at the modulemanager help) and put that menu-tag between the customcontent code
Re: Smarty - what is it?
Since this has nothing to do with smarty at all anymore i would suggest you to try this workaround how to create user specific content:
http://forum.cmsmadesimple.org/index.ph ... 185.0.html
http://forum.cmsmadesimple.org/index.ph ... 185.0.html