Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2024-08-13 15:08:06

lindabb
Member
Registered: 2023-02-17
Posts: 132

Pass articles (as text) to the plugin

I’m trying to write a special plugin for my site. I need to know if I can pass articles (as text) to the plugin, if not how I call articles inside the plugin passing ID.

Thank you

Offline

#2 2024-08-13 19:16:20

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,726
Website

Re: Pass articles (as text) to the plugin

I’m not sure how or if this helps your case but:

1. Textpattern stores the output of the current article in the global variable $thisarticle. For this you need to be on an individual article and have called a txp:article tag somewhere on your page. Then $thisarticle['Body_html'] is the html output of the body section, and so on for the other parts of the article. If you do the following inside an individual_article context:

global $thisarticle; dmp($thisarticle);

you get a dump of the variable with the names of the variable keys.

That’s fine if you’re only interested in the current article.

2. If you look at the source code, you’ll see that the article_custom function passes the task to parsearticles and then article_custom requests to the doArticles() function. Alternatively you can craft your own functions by querying the textpattern tables using Textpattern’s safe_query, safe_row, safe_field database functions in txplib_db.php (see the descriptions above each function).

3. A further option: you can parse txp tags from within php, e.g.:

$myvar = parse('<txp:article_custom id="1,2,3,4" form="my_form" break="" />');

4. And if you don’t need a full-blown plugin, you can write your tags normally in your page template, but instead of outputting to the page, you save it to a textpattern variable. You can then access that variable from inside a <txp:php> block to do something with it.

<txp:variable name="collected_article_images" trim>
     <txp:article_custom id="1,2,3,4" break=","><txp:custom_field name="article_image" /></txp:article_custom>
</txp:variable>

...

<txp:php>
    global $variable;
    // show the variable in php
    echo $variable['collected_article_images'];
</txp:php>

A trivial example but it shows you how you can pass information back and forth.


TXP Builders – finely-crafted code, design and txp

Offline

#3 2024-08-14 14:36:04

lindabb
Member
Registered: 2023-02-17
Posts: 132

Re: Pass articles (as text) to the plugin

Thank you so much, you are very helpful, I appreciate your time and support

Offline

Board footer

Powered by FluxBB