Using same template for single and multiple entries
Posted: 01 June 2007 11:06 AM   [ Ignore ]  
Grad Student
Rank
Total Posts:  54
Joined  06-01-2007

Is it possible to render the same page differently depending on whether the entry was accessed directly or if it is a summary listing?

I have a weblog set up where the user enters the title, the body, and a summary.  I want to make it so that when the user goes to /myblog/ or /myblog/index, they receive a listing of the titles of the posts with the summary.  Clicking on the title will send them to /myblog/urltitle and will render the post appropriately.

The problem that I am having is that I would like some of the other content on the page to be different depending on whether it is a page for a single post the page for the listing of all posts.  What’s the easiest way to determine if the page is rendering a single entry or multiple entries?  I can’t simply use {if total_results == 1} because there could be only one item in the listing when i paginate the results.

I’m sure this is a common way of using templates and would appreciate it if someone could shed some light on the subject.

Thanks

Profile
 
 
Posted: 01 June 2007 12:37 PM   [ Ignore ]   [ # 1 ]  
Grad Student
Rank
Total Posts:  54
Joined  06-01-2007

Here’s the solution I came up with.  I’m using two separate {exp:weblog} listings.  The first checks to see if the url_title is the same as the appropriate url segment.  If it is, the single element will be rendered.  Otherwise, the entries will be listed in a summary format.

<html><body>

{assign_variable:my_weblog="polls"}
{assign_variable
:my_template_group="polls"}

<pre> Segment vars
Seg1
: {segment_1}
Seg2
: {segment_2}
Seg3
: {segment_3}
Seg4
: {segment_4}
</pre>

<!--
Checking segment_2 and segment_3 because currently, /index/ is optional so the url title could be /polls/index/url_title or /polls/title/ -->
{exp:weblog:entries weblog="{my_weblog}" orderby="date" sort="desc" dynamic="on" limit="1"}
   {if
(url_title) && ((segment_3 == url_title) || (segment_2 == url_title)) }
      this is a direct entry
      
<h1>Page Header</h1>
   
{/if}
{
/exp:weblog:entries}    


{exp
:weblog:entries weblog="{my_weblog}" orderby="date" sort="desc" limit="5" }
   {if
(url_title) && ((segment_3 == url_title) || (segment_2 == url_title)) }
      
<!-- EE needs a NOT operator -->

   
{if:else}
      {if count
== 1}
         this is a listing
         
<h1>Page Header</h1>
      
{/if}
      {url_title}
<br/>
   
{/if}
{
/exp:weblog:entries}    

</body></html>
Profile
 
 
Posted: 08 June 2007 08:19 AM   [ Ignore ]   [ # 2 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2062
Joined  09-16-2004

Pretty cool you posted your own solution (and only 1 hour later smile )

 Signature 

Peace, e-man.
stookstudio.com, websites built with care and web standards. LinkedIn profile

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 1743, on December 02, 2009 03:47 PM
Total Registered Members: 120594 Total Logged-in Users: 71
Total Topics: 126635 Total Anonymous Users: 38
Total Replies: 665682 Total Guests: 385
Total Posts: 792317    
Members ( View Memberlist )