Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Outputting a variable that is defined further down the page?
I have a site with a series of longform text articles written by different authors. Each author has their own profile article on a pageless section containing a biography in different lengths, some contact details and their article image.
I want to output the author’s name under the heading but have the author’s biographic details at the end of the article. Remembering this thread, I thought I could do something clever and retrieve the author information at the bottom of the page where I want it, and then post-populate the author name at the top via post-processed variable. It didn’t work but I’m not sure why. This is the basic principle:
<txp:article>
<!-- title block in page_header form -->
<txp:variable[-1] name="page_author" wraptag="p" class="page-author" />
<!-- rest of article -->
<txp:output_form form="author_profile" />
</txp:article>
and the author_profile form has:
<txp:if_individual_article>
<txp:if_custom_field name="author_article_id">
<txp:article_custom id='<txp:custom_field name="author_article_id" />' wraptag="div" class="author-biography">
<txp:images id='<txp:custom_field name="article_image" />' limit="1">
<img src="<txp:image_url />" class="author-img" alt="<txp:image_info type="alt" />" width="<txp:image_info type="w" />" height="<txp:image_info type="h" />">
<txp:jcr_image_custom name="copyright" variable="author_img_credit" />
</txp:images>
<div class="author-desc">
<!-- this is where the variable is defined -->
<txp:variable name="page_author"><txp:title /></txp:variable>
<txp:variable name="page_author" wraptag="h3" class="author-name" />
<txp:body />
<txp:variable name="author_img_credit" wraptag='<p class="author-photo-credit">Photo: <+></p>' />
</div>
</txp:article_custom>
</txp:if_custom_field>
</txp:if_individual_article>
The author profile outputs perfectly, so that is all working but the author_name at the top does not. The tag trace shows:
<txp:variable[-1] name="page_author" wraptag="p" class="page-author" />
[<txp:variable>: Unknown variable 'page_author']
Any ideas what I am doing wrong?
(I know I could call the article_custom bit twice, or I could get the author details at the top of the page, store them in variables and output them lower down)
TXP Builders – finely-crafted code, design and txp
Offline
Re: Outputting a variable that is defined further down the page?
I expect it’s the among its txp siblings that’s catching you out. The output_form tag is the same level as the variable tag you want to output, but then the form goes “deeper” to set the value of the variable so the variable tag that outputs the page_author can’t “see” inside the form.
I might be way off, so please wait for Oleg to chime in. Perhaps -1 has special meaning? But I expect if you set the variable directly inside your article tag, towards the bottom (just as a test) it will show up because the tags are then siblings.
Perhaps varying the value in the square brackets to match the txp tag nesting depth that your variable assignment is done (4? 5? -4? -5?) will work? (I honestly don’t know as I’ve not delved into this much).
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: Outputting a variable that is defined further down the page?
Good tip. I guess I still don’t properly understand what among its txp siblings means.
You’re right. If I output the variable[-1] “alongside” but above the output_form tag, it works.
But putting it back where it belongs and varying the number didn’t help, unfortunately.
My site is a bit more complex than my pseudo code above:
<txp:if_article_list>
<!-- list stuff -->
<txp:else />
<txp:output_form form="page_header" /> <!-- txp:variable[-x] tag in here -->
<txp:output_form form="page_body" /> <!-- txp:variable defined in author_profile form in here -->
</txp:if_article_list>
And then there’s an additional article_custom in the author_profile form!!
Do perhaps the tag trace indentations provide any clues?
TXP Builders – finely-crafted code, design and txp
Offline
Re: Outputting a variable that is defined further down the page?
jakob wrote #342335:
putting it back where it belongs and varying the number didn’t help, unfortunately.
Drat. Was a long shot. Hopefully Oleg can swagger in with some insight because…
jakob wrote #342335:
I still don’t properly understand what among its txp siblings means.
(you and me both) :)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: Outputting a variable that is defined further down the page?
For the moment I resorted to defining variables at the page head and then using them later. I’d still like to understand what I was trying to do, though.
TXP Builders – finely-crafted code, design and txp
Offline
Re: Outputting a variable that is defined further down the page?
Among its siblings means that
<txp:hide process="1">
<txp:variable[-1] name="test" />
<txp:variable name="test" value="me" />
</txp:hide>
works as expected, but
<txp:hide process="1">
<txp:variable[-1] name="test" />
</txp:hide>
<txp:hide process="1">
<txp:variable name="test" value="me" />
</txp:hide>
does not. Your block should be
<txp:if_article_list>
<!-- list stuff -->
<txp:else />
<txp:output_form[-1] form="page_header" /> <!-- txp:variable tag in output here -->
<txp:output_form form="page_body" /> <!-- txp:variable defined in author_profile form in here -->
</txp:if_article_list>
Offline