feulf / raintpl3

The easiest Template Engine for PHP
https://feulf.github.io/raintpl
258 stars 57 forks source link

Problem while creating a tag #146

Open patrickse opened 10 years ago

patrickse commented 10 years ago

Hi,

I am trying to implement a Role-Based website. A few parts of my templates should be hidden when a user with a certain role enters the page. I´ve tried to use tags for this.

{hasRole("Admin")}
  Status
  Time
{/hasRole}

If the user has the role admin the content will be visible otherwise its not rendered onto the page.

I´ve created the extension and passed the regexp. But I am actually failing because it looks like that tags are no intended to use multiple lines of code.

Is there any other chance to achieve this behaviour without using the {if=""}-clause?

Hope you can help me...

Patrick

patrickse commented 10 years ago

I´ve solved my problem. I am now using the PluginFramework and replacing the tags with a call to a static function outside the template.

Now it works quite good.

feulf commented 10 years ago

Great!

From my iPhone

On Mar 31, 2014, at 10:18 AM, patrickse notifications@github.com wrote:

I´ve solved my problem. I am now using the PluginFramework and replacing the tags with a call to a static function outside the template.

Now it works quite good.

— Reply to this email directly or view it on GitHub.

keskad commented 10 years ago

In my framework I'm just checking permissions and passing it to variable eg. template -> push('isAdmin', true); and checking {if="$isAdmin"} ... {/if}. It's better to separate logic code from template, so you should'nt use permissions checking functions inside of template.