My First EE Site…
Posted: 12 May 2008 06:17 AM   [ Ignore ]  
Grad Student
Rank
Total Posts:  31
Joined  05-12-2008

Hi,

Apologies if this post is in the wrong section.

I’m evaluating EE Core to build a website, with the view of upgrading to a commercial license if all goes well.

Now, I’m used to creating php/mysql based sites using index.php as a master template with sub-templates being included into index.php based on a query string.
e.g.
www.domain.com/index.php?section=home = Homepage
www.domain.com/index.php?section=news = News Page
www.domain.com/index.php?section=news&id=12 = News Item #12

So I’m building my templates in EE at the moment, and ideally those same URLs should equate to something like:
www.domain.com/index.php/home/
www.domain.com/index.php/news/
www.domain.com/index.php/news/news_story_title

I realise that index.php/home is one template group and index.php/news is another. However, both of these template groups will contain large amounts of duplicate code.

In my main template snippet below I’ve stripped out the header/footer into sub-templates, as these are constant. However I will need to embed the correct layout template based on which page is requested.

<div id="wrapper">
    
{!-- Include Page Mast --}
    {embed
="inc/pg_mast"}
    
    {
!-- Include layout based on section (one of: home, news, ...) --}
    {embed
="layouts/home"}
    
    {
!-- Include Page Footer --}
    {embed
="inc/pg_footer"}
</div>

If I were building a normal PHP site, the embeds would be include() calls, and the layout call would be something like include(‘layouts/’.$_GET[‘section’].’.php’);

I can think of two (not very suitable) solutions to do this in EE:
1. Create the site with one master template and use query strings and php code to identify and determine sections.
2. Create duplicate templates with identical code except for the {embed=“layouts/home”} line.

I hope I’m making sense with all this? Can anyone think of a better solution?

Ideally there should be one master template which loads a dynamic sub-template based on the page requested.

Profile
 
 
Posted: 12 May 2008 08:54 AM   [ Ignore ]   [ # 1 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6092
Joined  08-04-2002

You could probably use url segments…I haven’t used it with embeds but should work I’d think…

{!—Include layout based on section (one of: home, news, ...)—}
  {embed=“layouts/
{segment_1}”}

Profile
 
 
Posted: 12 May 2008 10:14 AM   [ Ignore ]   [ # 2 ]  
Grad Student
Rank
Total Posts:  31
Joined  05-12-2008

Thanks PXLated, that may work. I’d guess I would need a htaccess hack to override all urls to the same template.

On another note, I’ve tried using the following code, where {default_section} is a global string variable.

{embed=”{default_section}/index”}

This doesn’t appear to work. My guess would be that I’m missing an operator to concat the two strings. I’m not sure if EE even supports string manipulation like this.

I’ve also tried the following in the template with no success:
{embed={default_section}.”/index”}
{embed={default_section}+”/index”}

Maybe I should be using PHP in the template instead to do this?

Profile
 
 
Posted: 12 May 2008 10:20 AM   [ Ignore ]   [ # 3 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32921
Joined  05-14-2004

How about passing the variable via the embed?

Also, user defined global variables can be used in EE tags.  You could instead use path.php variables.

In any case, I’m going to move this down to how-to, since you’re working through a solution. =+)

 Signature 
Profile
MSG
 
 
Posted: 12 May 2008 10:34 AM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  887
Joined  02-15-2008

I do this on every EE site I’ve worked on so far, using the method Lisa mentions above, via embed:

{!-- Include layout based on section (one of: home, news, ...) --}
{embed
="layouts/home" section="section_name"}

You can then use this variable in your home embed with something like:

{if embed:section=="home"}
{if
:elseif embed:section=="news"}
{if
:else}
{
/if}

Perfick!

 Signature 

Andy Harris | Pepper Digital | Malvern, UK | Twitter | New to ExpressionEngine? Start here!
Remember - If at first you don’t succeed, you’re not Chuck Norris

Profile
 
 
Posted: 12 May 2008 10:36 AM   [ Ignore ]   [ # 5 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6610
Joined  04-15-2006

Hiya,

I must admit I’m a little confuddled on exactly what it is that you are trying to do here. If you are after (and I could be wrong on this, please let me know if I am) having a different style to the page based upon what entry or section you are in then the latter would be taken care of by correct usage of the template_group->template hierarchy scheme.

Say for instance you wanted a section to show all your news posts you would have something like this :

http://www.example.com/news/

This would contain a weblog tag to spit out all the news entries using whatever parameters you need to limit the output (if you want to limit them that is). Next up let’s say that each of the news items on that page has a read more link and when you go to read more for those news items you wanted a different style to the page then all you would have to do is point the links to say something like :

http://www.example.com/news/detail/news_item_title

and then you would place slightly different styling into the news/detail template to take care of that for you.

If on the other hand you want different styling based on the actual entry you are viewing then this could be handled by having a custom drop-down field in your weblog which holds names such as :

light
dark
bright

You could then place a conditional into the template to place different layout code into the page based upon what that field contains. Something along the lines of :

{embed="includes/{custom-field-value}"}

You could then have templates called light, dark & bright which would refer to the value that you placed into the custom field for each entry.

Don’t know if that is what you are trying to accomplish though as I must admit I was a little confused with the explanation above due to the way you used to do things but please don’t take that as a bad thing it’s just that I have never done that before so didn’t quite understand it wink

Hope some of that throws some ideas your way though?

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 12 May 2008 12:40 PM   [ Ignore ]   [ # 6 ]  
Grad Student
Rank
Total Posts:  31
Joined  05-12-2008

thanks for all your help grin
I think Lisa / Andy are on the right lines.
I didn’t realise you can embed and pass through a variable like that… very neat!

I’m actually at home now, I’ll let you know how I get on with it tomorrow.

I don’t think the template_group/template layout would work well for me. The problem is that the root (index) of each template group would have to duplicate the same HTML structure.

i.e.

<!-- Header Chunk -->
...
<!--
Home/News/etc Content Chunk -->
...
<!--
Footer Chunk -->
...

Using the embeds, I should be able to create one single template which loads a dynamic content chunk (rather than hardcoding it in the root of each template group).

Again thanks for all your help.
Its much appreciated. grin

Profile
 
 
   
 
 
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: 65087 Total Logged-in Users: 37
Total Topics: 82226 Total Anonymous Users: 21
Total Replies: 441924 Total Guests: 211
Total Posts: 524150    
Members ( View Memberlist )