Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2012-01-25 06:09:31
- mmelon
- Member
- Registered: 2006-03-02
- Posts: 95
article custom returning weird empty string in variable assign
Hi,
I am trying to test for articles in a section (with a flag of show on main nav) before I render a subnav.
<txp:variable name="has-nav">
<txp:article_custom section="about" show_main_nav="_%" />
</txp:variable>
this sets the variable ‘has-nav’ to the data returned from the articles and I can test for it.
The weird thing is, if there are no articles I would expect it to return nothing and null the variable.
<txp:variable name="has-nav">
<txp:article_custom section="blah" show_main_nav="_%" />
</txp:variable>
on a non existent section, still returns true on a <txp:if_variable name=“has-nav”> test
I investigated further and this
<txp:php>var_dump(variable(array('name'=>'has-nav')));</txp:php>
is giving me
string(45) “ “
on a variable i was hoping to be empty?
What am I doing wrong? Is there a better way?
Kind regards,
Mike
Offline
#2 2012-01-25 06:10:46
- mmelon
- Member
- Registered: 2006-03-02
- Posts: 95
Re: article custom returning weird empty string in variable assign
hey I bet that string is textpattern returning that ‘it couldn’t find the section’ :( !!
Offline
Re: article custom returning weird empty string in variable assign
mmelon wrote:
hey I bet that string is textpattern returning that ‘it couldn’t find the section’ :( !!
It’s the white-space. If you have a space, newline or tab character wrapped in the variable tags (or in the value), it will carry over. In the code you posted, the variable will never be empty. Strip the white-space and you are good to go. I.e.
<txp:variable name="has-nav"><txp:article_custom section="blah" show_main_nav="_%" /></txp:variable>
Btw, Textpattern’s error messages are triggered are handled by error handlers, not directly returned by tags. Error messages will (except for some exceptions) appear at the top of the page and won’t interfere with the page template, code or content.
Offline