variables
Posted: 23 May 2008 05:21 PM   [ Ignore ]  
Grad Student
Rank
Total Posts:  64
Joined  01-05-2008

I’m sure people have mentioned this before, I develop in EE alot and I am always running into the same problem of not being able to create any dynamic variables.  If I want to decide which categories to show based on a segment, then it would be nice to simply have a variable I could assign within a loop to do that.  I run into this on almost every project and I usually have two options, write sloppy EE code that has my code recopied for every instance within a If then Else statement or use PHP, which I really try to avoid doing.  It wouldn’t have to be very robust, but it would add a great degree of functionality if we could just assign dynamic string vars.  I bet there’s a good reason this isn’t already a feature, but I know several people who do EE development, and they’ve run into the same problem. 
BTW-  EE is an awesome product!

Profile
 
 
Posted: 27 May 2008 09:50 AM   [ Ignore ]   [ # 1 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15842
Joined  06-03-2002

The reason is two-fold, Kev-O, and I’ll try to explain.

First, show me any conditional and I can give you an example of it used in a context of where the developer does want it parsed and evaluated in time to create a variable, and another where they would not want it parsed at that time.  Because people wish to do so many things in the templates, EE can only be predictive to a degree within the confines of things taking place in a particular order.

Second is that with thoughtful template design and URL structure, that type of assignment is often unnecessary, as ExpressionEngine has many ways to automatically constrain tag output with semantic and useful URLs.  In the cases that it does not meet your needs, these segment conditionals you refer to can simply call a shared embedded template, passing the necessary variable via an embed variable.  The result is that you end up with cleaner looking templates, and have less duplicated code.

 Signature 
Profile
MSG
 
 
Posted: 27 May 2008 07:51 PM   [ Ignore ]   [ # 2 ]  
Grad Student
Rank
Total Posts:  64
Joined  01-05-2008

Yeah right on, I get it.  Hadn’t thought of using embedded templates for conditional segments, thats a really good idea.  Thanks for the explanation…

Profile
 
 
Posted: 06 July 2008 11:03 PM   [ Ignore ]   [ # 3 ]  
Summer Student
Total Posts:  8
Joined  06-22-2008

Ah ha.. embedded templates as a sort of a little call back routine. Isn’t this expensive in EE template passing?

Profile
 
 
Posted: 07 July 2008 07:29 AM   [ Ignore ]   [ # 4 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15842
Joined  06-03-2002
Hinterlands - 06 July 2008 11:03 PM

Ah ha.. embedded templates as a sort of a little call back routine. Isn’t this expensive in EE template passing?

Not in normal circumstances.  Turn on your template parsing log and you’ll be able to see the time and memory increase.  Where it can become expensive is when you start doing some really silly things with embeds, such as a weblog entries tag within an template that gets embedded a hundred or so times in a loop.

 Signature 
Profile
MSG
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64982 Total Logged-in Users: 32
Total Topics: 82024 Total Anonymous Users: 23
Total Replies: 440857 Total Guests: 182
Total Posts: 522881    
Members ( View Memberlist )
Newest Members:  ariepChris Bandytony leodennisbaldwinhazlett_davidkpspokeli9htcluizmbentsitj