Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2022-06-02 16:03:21

Myusername
Member
Registered: 2019-12-12
Posts: 162

Exclude attribute not working with dynamic values?

I’m trying to iterate <tag:article /> and store the id of each article in a variable called ‘ids’, like this:

<txp:article>
  <if::first_article>
    <txp:variable name="ids" value='<article::id />' />
    <txp:else />
    <txp:variable name="ids" value='<txp:variable name="ids" />, <article::id />' />
  </if::first_article>
</txp:article>

The idea is later in another section to remove these articles from a txp:article_custom tag like this:

<article::custom exclude='<txp:variable name="ids" />' limit="5" />

But the thing just doesn’t work. The output of the variable is: 299, 298, 297, 296, 295, I already made sure of that. But the articles are only removed if I manually put these ids in the exclude attribute. Dynamically, it doesn’t work. Any reason for this to happen? I’m using v4.9.0-dev

Offline

#2 2022-06-02 17:17:32

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,595
GitHub Twitter

Re: Exclude attribute not working with dynamic values?

Hi.

Maybe you need to include the add attribute into you ids variable?


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#3 2022-06-02 17:50:44

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,303

Re: Exclude attribute not working with dynamic values?

Myusername wrote #333510:

The idea is later in another section to remove these articles from a txp:article_custom tag

Like “later in another page”? Isn’t a variable page specific and needed to be stored somewhere in order to be accessible in a different page?


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#4 2022-06-02 18:20:20

Myusername
Member
Registered: 2019-12-12
Posts: 162

Re: Exclude attribute not working with dynamic values?

Well, it was my mistake. I was giving the variable’s value inside a form that was called later on the page, however that same form was being used elsewhere and it was changing the variable’s value. I made a mess, but it’s already resolved, thanks anyway

Pat64 wrote #333511:

Maybe you need to include the add attribute into you ids variable?

Although the problem is not that, thanks for the tip, it left the code cleaner. I didn’t know about this possibility, I should probably go back and take a look at the variable tag documentation

Offline

#5 2022-06-03 04:45:37

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,595
GitHub Twitter

Re: Exclude attribute not working with dynamic values?

… Try to remove the space into:

<txp:variable name="ids" value='<txp:variable name="ids" />, <article::id />' />

This one get a comma separated list of ids without any spaces:

<txp:variable name="ids" value='<txp:variable name="ids" />,<article::id />' trim />

Last edited by Pat64 (2022-06-03 04:57:48)


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#6 2022-06-03 11:49:59

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Exclude attribute not working with dynamic values?

For the record, that’s how one makes a list with add:

<txp:variable name="ids" add='<article::id />' separator="," />

If you don’t set separator, article ids being numeric, you’ll get their sum (just a commodity).

Spaces shouldn’t be a problem for use in exclude and most other attributes.

Offline

#7 2022-06-11 06:59:45

Myusername
Member
Registered: 2019-12-12
Posts: 162

Re: Exclude attribute not working with dynamic values?

One more question about this attribute. Can I somehow remove articles from the output that contain a custom field that has a certain value? For example:

<txp:article_custom exclude='<article::id />, custom_4="some_value"'>
    <!-- -->
</txp:article_custom>

Something makes me think there’s an easy way to do this, but it’s running out of my mind

Last edited by Myusername (2022-06-11 07:02:05)

Offline

#8 2022-06-11 09:54:23

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Exclude attribute not working with dynamic values?

You can try

<txp:article_custom exclude='<article::id />, cf_name' cf_name="some_value">
    <!-- -->
</txp:article_custom>

Offline

#9 2022-06-11 17:59:47

Myusername
Member
Registered: 2019-12-12
Posts: 162

Re: Exclude attribute not working with dynamic values?

etc wrote #333580:

You can try

Thanks for the help (again, as always), it worked perfectly

Offline

Board footer

Powered by FluxBB