php - Using same variable names in files added with get_template_part()

Say I have a file named content-header.php and content-body.php.In content-header.php I have this variable:$some_var = &

Say I have a file named content-header.php and content-body.php.

In content-header.php I have this variable:

$some_var = 'apples';

and in content-body.php I have a variable with the same name but different value:

$some_var = 'bananas';

In another file I use:

get_template_part('content', 'header');
get_template_part('content', 'body');

Would $some_var be limited to its own file or overwrite the other? Is it ok to use same variable names in files added through get_template_part()?

Would I have to use unique variable names?

Say I have a file named content-header.php and content-body.php.

In content-header.php I have this variable:

$some_var = 'apples';

and in content-body.php I have a variable with the same name but different value:

$some_var = 'bananas';

In another file I use:

get_template_part('content', 'header');
get_template_part('content', 'body');

Would $some_var be limited to its own file or overwrite the other? Is it ok to use same variable names in files added through get_template_part()?

Would I have to use unique variable names?

Share Improve this question asked Jun 5, 2019 at 20:16 at least three charactersat least three characters 33712 silver badges28 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

You can absolutely use the same variable names. Arguments like that do not pass through from one template to another without a little help from a function.

So if in content-header.php you have $fruit = banana; and in content-body.php you have $fruit = apple; you will not have a conflict. Go nuts. Or bananas. ;)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745433686a4627510.html

相关推荐

  • php - Using same variable names in files added with get_template_part()

    Say I have a file named content-header.php and content-body.php.In content-header.php I have this variable:$some_var = &

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信