Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Template code to get value of compile_id? smarty3

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
phil_karasinsky
Smarty n00b


Joined: 14 Nov 2015
Posts: 4

PostPosted: Sat Nov 14, 2015 11:31 pm    Post subject: Template code to get value of compile_id? smarty3 Reply with quote

How can I retrieve the compile_id within a smarty3 template?

For example, I wish to reference the compile_id in an {if} block:

Code:
{if $please_tell_me_what_this_should_be.compile_id=="x"}
  {* do some stuff *}
{/if}

I know I could have my PHP program pass the value using assign() and have my template view that. However, I don't want to do that (for application-specific reasons that I don't want to elaborate on).

I'm using smarty 3.1.27.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sun Nov 15, 2015 5:14 am    Post subject: Reply with quote

You shouldn't do THAT in a template, not with compile_id.
compile_id produces a separate compiled version of the template. Given your example, each of these versions will include the same code, which raises a question of what you really trying to achieve here with different compile_id's.
Even if we step down and discuss cache_id, you don't need to know that either.
You must not base your template logic on outside knowledge. And knowing technical metadata is an outside knowledge.
If you want to change your template behavior from your application code (i.e. by passing special variables you think template is checking), you should really reconsider your application logic.
Probably, you need more than one template. Probably, you didn't read inheritance rules or did not gave them a good thought.
Simple rule is to only work your template from explicit knowledge. From the data you have assigned to it directly. That is, Smarty::assign();…
Back to top
View user's profile Send private message
phil_karasinsky
Smarty n00b


Joined: 14 Nov 2015
Posts: 4

PostPosted: Sun Nov 15, 2015 11:18 am    Post subject: Reply with quote

Hi AnrDaemon,

Thanks for your reply. On reflection I can see that you are correct.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Nov 16, 2015 9:11 am    Post subject: Reply with quote

As an afterthought, probably an example givein in the http://www.smarty.net/forums/viewtopic.php?t=25486 may be of use to you.

The one benefit of {extends} versus {include} is that {extends} produces one compiled template for its inheritance chain. (In that mentioned example, 3 template sources will produce one compiled template).
Back to top
View user's profile Send private message
phil_karasinsky
Smarty n00b


Joined: 14 Nov 2015
Posts: 4

PostPosted: Mon Nov 16, 2015 2:40 pm    Post subject: Reply with quote

Thanks for the pointer.

I'm glad I posted the question that I did. Although my original thinking arose from a flaw in my conceptualisation at the "project level" and I don't actually need to do anything equivalent to what I was asking for, I can see that template inheritance would help parts of my design. This includes the part whose faulty planning spurred my question Smile
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP