PHP Hook for L&L output

I want to use PHP to modify the output of an L&L template. Are they considered shortcodes, and if so, what is the tag?

My template is [template id=57591]

Here’s what I’m trying.

add_filter( 'do_shortcode_tag','my_mods',10,3);

function my_mods( $output, $tag ) {
	if ( '[template id=57591]' !== $tag ) {
		return $output;
	}
	return $output . 'whatever i want to modify' ;
}

Looks like there are a couple of different options depending on what you’re trying to do using the tangible_template PHP function. That’s out of my depths though so I won’t be able to do much more than point you in that direction, but hopefully someone else on the forum can provide some more specific guidance if you need it.

1 Like

Thanks @benjamin

I’m not quite sure what to make of echo tangible_template('<Field title />');

It seems like I would need to enter my entire template inside the parentheses rather than somehow referencing the name of an existing template. e.g. something like echo tangible_template('name-of-my-saved-template');

I can generally figure things out once I’m in PHP, but, as usual, the challenge is to figure out how to interface with things outside of PHP.

Yeah I haven’t played around enough with PHP to know exactly how you’d structure that. But I assume you could use the Template tag like echo tangible_template('<Template id=123 />'); to render your template without needing to put the whole thing in the parentheses.

1 Like

Success! This is a specific application, but the principles might apply to anyone else wanting to hook the output of a Tangible Template.

I was originally displaying my template like this [template id=57591]

My goal was to change the color of certain words in the output, so I created this shortcode with a Snippet

add_shortcode( 'rs-highlighter', 'rs_highlight_text' );

function rs_highlight_text () {
	$search  = "highlight me";
	$replace = "<span style='color: yellow;'>highlight me</span>";
	$subject = tangible_template('<Template id=57591 />');

	return str_replace($search, $replace, $subject);	
} 

Now, wherever I want my output, I replace the original template shortcode with my new shortcode
[rs-highlighter]

Works great (make sure you clear caches when testing). Next, I might pass along parameters so I can use this with any template and any text.

Cheers, Richard