Nest HTML content between template part
Apologies for the lackluster title. I am curious if there’s something similar in WordPress as Nunjucks call or block.
Essentially, I am curious if it is possible to create a template part and inject html markup somewhere within that template part.
Currently I am accomplishing this by passing a variable, that contains my markup, to the template part. Example below:
template-part.php
<?php $markup = get_query_var("markup"); ?>
<div class="container">
<?php echo $markup ?>
</div>
page.php
<?php
$markup = "
<div>content</div>
";
set_query_var("markup", $markup);
get_template_part("partials/template-part");
?>
However, I would prefer a method that would look similar to this (obviously I using fictional method names here):
page.php
<?php start_template_part("partials/template-part"); ?>
<div>content</div>
<?php end_template_part("partials/template-part"); ?>
Is there something similar in WordPress that would allow me to accomplish the second method?
Leave an answer