Jump to content

Subfields in wirePopulateStringTags function


Andrey
 Share

Recommended Posts

Hello,

How are subfields supposed to work in wirePopulateStringTags. Tried object, WireData and even Page.

$parse_data = new WireData();
$parse_data->page1 = $page;
$parse_data->page2 = new WireData();
$parse_data->page2->setArray($page->data);
$parse_data->set('page3',(object)$page->data);
$parse_data->set('page4',(object)$page->getArray());
$txt = wirePopulateStringTags($page->body,$parse_data, array('removeNullTags' => false) );

echo $txt;

All of the tags {page1.title} {page2.title} {page3.title} {page4.title} are empty.

I'd like to use two objects like $user and $order (both are pages) to parse tags related to them, like user.username and order.order_user.username.

Thank you.

Link to comment
Share on other sites

Subfield addressing is implement by the Page class itself, so you're out of luck if you pass in anything else. If your properties are all tied to $page, it should work. Though, in any case, getting $page->body already calls wirePopulateStringTags implicitly when it encounters a replacement tag, so your tags will already have been replaced/emptied when you pass it to your own call to wirePopulateStringTags.

I'm not sure what problem you're trying to solve, but if it's about giving editors an easy means to include loosely related information in the HTML they enter, without needing to code themselves, it may be worth looking at the Hanna Code Textformatter, which lets you define your own tags and assign the PHP code that generates the replacement value.

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...