Problems with assign_variable within if conditionals
Posted: 15 May 2008 01:41 PM   [ Ignore ]  
Grad Student
Rank
Total Posts:  79
Joined  02-06-2007

I’m using one comment template to serve 4 or 5 weblogs.  I’m using conditionals to display the weblog information and within those conditionals I am assigning a variable to help assign the weblog information to the comment form after.

So it kinda looks like this:

<div class="entry">

{exp:weblog:entries}

{if weblog_id
=="15"}
        {assign_variable
:my_weblog="links"}
      
!--show entry info here--!
{/if}

{if weblog_id
=="17"}
        {assign_variable
:my_weblog="audio"}
      
!--show entry info here--!
{/if}
{
/exp:weblog:entries}

{exp
:comment:form weblog="{my_weblog}" preview="blog/comment_preview"}
!--comment form---!
{/exp:comment:form}

Originally these were “advanced” conditionals (if’s and if:else’s) but after reading this link, switched them to basic conditionals (thinking the parse order would help).

Why is this not working and is there another way to make it happen?

Profile
 
 
Posted: 15 May 2008 01:55 PM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15408
Joined  05-15-2004

You can’t do that. It’s still a parse order issue, you cannot dynamically reassign variables like that. If you’re thinking in terms of PHP, they’re really more like constants. If you need that level of flow control, you probably have to use PHP, or find yet another way.

 Signature 

Everything will be good in the end. If it’s not good, it’s not the end.

Profile
MSG
 
 
Posted: 15 May 2008 02:01 PM   [ Ignore ]   [ # 2 ]  
Research Assistant
RankRankRank
Total Posts:  403
Joined  02-14-2007

I’m not quite sure WHY, but my guess is that you are making it quite harder than it needs to be.  I think you are still running into a parse order issue; but I’d have to see the full code to be sure.

EDIT: I see Ingmar posted before me.  Here’s the issue, most likely—each one of those assign statements takes effect; so that the last one is the one that works.  I.E. every time the page is loaded, my_weblog will be assigned all of the values in a row, ending up with audio. 

My recommendation is this:  where are you getting the weblog_id from?  Most likely, the URL—in which case, why not let the ULR features of EE work for you?  You either have this on a template that only serves one weblog at a time, in which case I recommend the {segment_XX} variables, or you have this on a multi-weblog page, which makes thing a bit harder for you.

But in any case, the comment form on the same page as a weblog will use the same weblog, I think.  For a multiple page blog, the same principle applies as above: use the URL segment feature.

To address your question further: what, exactly, is breaking?  Is it the entry form or the comment form? 

You can also do this with php in the template (PHP parsing on input) as follows:

<div class="entry">

{exp:weblog:entries}

{if weblog_id
=="15"}
         <?php $my_weblog
= "links"; ?>
        
      
!--show entry info here--!
{/if}

{if weblog_id
=="17"}
        <?php $my_weblog
= "audio"; ?>
      
!--show entry info here--!
{/if}
{
/exp:weblog:entries}

{exp
:comment:form weblog="<?php echo $my_weblog; ?>" preview="blog/comment_preview"}
!--comment form---!
{/exp:comment:form}

That should do it for sure.

Profile
 
 
Posted: 15 May 2008 02:51 PM   [ Ignore ]   [ # 3 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15408
Joined  05-15-2004

J. Hull, does that explanation make sense? You could also try Vanceones’s code.

 Signature 

Everything will be good in the end. If it’s not good, it’s not the end.

Profile
MSG
 
 
Posted: 15 May 2008 03:17 PM   [ Ignore ]   [ # 4 ]  
Grad Student
Rank
Total Posts:  79
Joined  02-06-2007

Yes that is what is happening - although it’s always assigning the first value in the list of conditionals (links) regardless of where it came from.

As far as what is breaking - it’s the comment form - it’s not showing up at all.

I’m getting the weblog_id number from within the Weblog Entries tag.  The URL which calls this template is:

http://[sitename]/blog/comments/[entry-title]

The templates for the various weblogs lie within the blog template group (blog/links, blog/audio, etc.).

They end up calling this template with either a {comment_url_title_auto_path} if there are no comments, or a title_permalink=”/blog/comments” if there are.  This is the code for that call:

{exp:comment:entries limit="1"}

{if no_results}
{exp
:weblog:entries}
<p><a href="{comment_url_title_auto_path}#comments">Add Comment</a></p>
{/exp:weblog:entries}
{
/if}

<p><a href="{title_permalink="/blog/comments"}#comments">{total_comments} Comments</p>
    
{/exp:comment:entries}

So I guess the question now is there anyway I can send the weblog name along with this URL call?  And the next would be is this not the Standard Operating Procedure for comments for multiple weblogs.  Do most have separate comments template for each weblog?

Profile
 
 
Posted: 15 May 2008 04:24 PM   [ Ignore ]   [ # 5 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  12395
Joined  04-29-2002

J. Hull, in order for comments to work, you need the following:

A single entry template with a url_title passed in the segment.

Example:

http://www.example.com/index.php/site/comments/this-is-my-title

EE “sees” the this-is-my-title part of the URI and uses that to work with the rest of the code in the template.

Do you still have the original set of templates? It has an example of working with comments.

Site Themes

You can create a single comment template that works with multiple weblogs. It just takes more work. It depends on if you have different custom field groups.

 Signature 

Quick Reference - EE Trial Options - EE Wiki - Docs for updating a build

Profile
MSG
 
 
Posted: 15 May 2008 06:51 PM   [ Ignore ]   [ # 6 ]  
Grad Student
Rank
Total Posts:  79
Joined  02-06-2007

I have comments working fine if I pass the weblog information along with the comment:form tag. (I used the site themes as an example, along with stuff I learned from the docs).

The problem occurs when I try to use conditionals to assign that information within the comments template.

I have different custom field groups assigned for each weblog.

Profile
 
 
Posted: 15 May 2008 07:15 PM   [ Ignore ]   [ # 7 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  12395
Joined  04-29-2002

Can you save your template as a text file, zip it up and attach it as a zip file?

 Signature 

Quick Reference - EE Trial Options - EE Wiki - Docs for updating a build

Profile
MSG
 
 
Posted: 16 May 2008 12:45 PM   [ Ignore ]   [ # 8 ]  
Grad Student
Rank
Total Posts:  79
Joined  02-06-2007

Thanks - I’m gonna use vanceone’s php technique for this.

Profile
 
 
Posted: 16 May 2008 01:10 PM   [ Ignore ]   [ # 9 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15408
Joined  05-15-2004

Yes, that’s certaily a solution. Glad you’re all set.

 Signature 

Everything will be good in the end. If it’s not good, it’s not the end.

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: 64978 Total Logged-in Users: 32
Total Topics: 82017 Total Anonymous Users: 22
Total Replies: 440822 Total Guests: 191
Total Posts: 522839    
Members ( View Memberlist )