Trouble with blocks in non-template php page

I am having trouble loading blocks into a non-template php page.

I have pasted in the embed code but it doesn’t load on the PHP page. Any tips of what may be causing the issue from experience?

Pulse short codes are only processed within the main Pulse content area of a template;

<?php echo $parsedown->text($content); ?>

This would typically pull in the page content which in turn could include blocks, galleries, blog posts etc. Your short codes can live in any of these items but outside of the content area you’ll have to pull them in using a regular PHP include;

<?php include_once("content/blocks/common/footer-address.txt"); ?>
1 Like

Thanks, that worked perfectly. I couldn’t find anything on this in the manual.

I am also having trouble adding galleries into the blocks to show on my non-template page.
I have added in the tag into the block {{gal:galname}} but it then just shows this on the frontend and doesn’t load the gallery

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.

Hi Dan,
Apologies for the delayed reply.

Pulse will automatically handle the replacement of plugin short codes for you if (and only if) the item is a child of that include code we looked at earlier;

<?php echo $parsedown->text($content); ?>

Any page, block or blog post that gets displayed through this tag will be fine. Outside of this if we pull in our content from a regular PHP include (of example) then any short codes normally wouldn’t be processed and your {{gal:gal name}} tags will simply show up on the page.

To get around this you can use a modified version of PHP’s own include function that swaps out the short codes when the item is included.

Copy and paste the code at the end of this post into a plain text file called tpinclude.php (for example) and save it in the root of your site (next to the index.php file) and add the following include to your layout.php file;

<?php include_once("tpinclude.php"); ?>

You can then use the this custom function in your template to pull in and replace the short code tags;

<?php tpinclude("content/blocks/common/footer-address.txt"); ?>

I hope this helps.


//tpinclude - include blocks outside of the main Pulse page area and still process Pulse tags

function tpinclude($tpblock){

	$tpblockcontent     = file_get_contents($tpblock);
	if (preg_match_all("/".'(\\{)'.'(\\{)'.'.*?'.'(\\})'.'(\\})'."/", $tpblockcontent, $m)) {   
		foreach ($m[0] as $get_embed1) {       
			$get_embed = $get_embed1;
			$get_embed = str_replace("{", "" ,$get_embed); 
			$get_embed = str_replace("}", "" ,$get_embed);  
			if (substr_count($get_embed, ':') >=1 ) {                        
				$exp = explode(':', $get_embed); 
				$vars = array_slice($exp, 1); 
				$tag_var1 = (!empty($vars[0])) ? $vars[0] : '';
				$tag_var2 = (!empty($vars[1])) ? $vars[1] : '';
				$tag_var3 = (!empty($vars[2])) ? $vars[2] : '';
				$get_embed = $exp[0];
			if($get_embed == 'template'){ $new_template = $tag_var1; }
			else { include("inc/tags/$get_embed.php");
			$new  = ob_get_contents();}
			$tpblockcontent = str_replace($get_embed1, $new, $tpblockcontent);

1 Like