0

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.