Passing variables to template parts

Question

I have one template file videos.php which has the following line of code in it (aswell as a load of HTML):

<?php get_template_part('loop', 'feed-videos' ); ?>

inside that template part, I have the following:

<?php $video = 'video-' . $post->ID; ?>
<?php get_template_part( 'include', 'modal-video' ); ?>

I would then like to be able to use the $video variable inside include-modal-video.php.

So at the top of include-modal-video.php I have:

<?php global $video; ?>

Further down that file, I have <h2>00: <?php echo $video; ?></h2>

But I get nothing output from that line of code. All I see is the following indicator of where the value should be

00

Can anyone see what Im doing wrong?

0
, , , , pealo86 3 years 2020-08-27T17:10:29-05:00 0 Answers 57 views 0

Leave an answer

Browse
Browse