Nest HTML content between template part

Question

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?

0
, , , , justinw 3 years 2020-04-03T12:52:07-05:00 0 Answers 86 views 0

Leave an answer

Browse
Browse