沉冰浮水

沉冰浮水

做最终到的事,成为最终成为的人!
github
bilibili
mastodon
zhihu
douban

"Waterhole" Z-BlogPHP Template Mechanism Explanation "Simple Version"

title: "Introduction to Z-BlogPHP Template Mechanism (Simple Version)"
date: 2021-08-14 18:33:04
tags:

  • GesF-Force
  • Z-BlogPHP
  • PHP
    categories:
  • Computer Network
    id: 2423
    alias: 20201026266

Routine Second Time#

It seems that there are indeed many things, but I don't know what they mean in daily life;

Summary of Z-BlogPHP template syntax:

https://docs.zblogcn.com/php/markup/

"Small Goal" earns 1 yuan per article/Git Repository on average_Miscellaneous_Sinking Ice and Floating Water:

[https://www.wdssmq.com/post/20210723266.html](https://www.wdssmq.com/post/20210723266.html "Small Goal" earns 1 yuan per article/Git Repository on average_Miscellaneous_Sinking Ice and Floating Water)

Why is it called "Water Pit":

[Index of "Water Pit" Tutorial Series](/post/20200617652.html "Index of "Water Pit" Tutorial Series")

PHP Variable Variables (Dynamic Variables)#

// Zero - index.php
echo "<h3>Zero</h3>";
$animal = 'turtles';
$turtles = 103;
print $$animal;
// The output here is the same as:
// print $turtles

Using this syntax, the view layer (View) can be separated to achieve the "template mechanism";

Reference:
"PHP: Variable Variables - php.net"
"MVC Framework_Baidu Baike"
;

Main Text#

Note: The part in the comment - index.php indicates which file the code should be placed in;

// Data for display - index.php
$tags = array(
  "blog" => "https://www.wdssmq.com",
  "name" => "Sinking Ice and Floating Water",
  "afdian" => "https://afdian.net/@wdssmq"
);

Output each item of the above array as a paragraph;

// One - index.php
echo "<h3>One</h3>";
foreach ($tags as $key => $value) {
  echo "<p>{$key}: {$value}</p>";
}

// Two - index.php
echo "<h3>Two</h3>";
foreach ($tags as $key => $value) {
  $$key = $value;
}
echo "<p>name: {$name}</p>";
echo "<p>blog: {$blog}</p>";
echo "<p>afdian: {$afdian}</p>";

Method "One" is a basic loop usage, and the output order is consistent with the element order when assigning variables;

Method "Two" uses the "variable variable" syntax to create a separate variable for each element in the array, with the variable name being the key name (field name) of each array element;

Then adjust the order when outputting, so you don't need to care about the original definition;

// Three - index.php
echo "<h3>Three</h3>";
foreach ($tags as $key => $value) {
  $$key = $value;
}
include "user-info-3.php";

Continue to add the above code to "index.php", then create "user-info-3.php" in the same directory and add the following code;

<?php
// 3 - user-info-3.php
echo "<p>name: {$name}</p>";
echo "<p>blog: {$blog}</p>";
echo "<p>afdian: {$afdian}</p>";

Continue to improve:

// Four - index.php
echo "<h3>Four</h3>";
foreach ($tags as $key => $value) {
  $$key = $value;
}
include "user-info-4.php";

Note that all the code written in "index.php" or "user-info-3.php" above is within <?php;

Little knowledge: For PHP syntax, remember <?php ?>, when there is no need to close in the middle to insert HTML, the ending ?> used to end can be omitted;

The code for the "user-info-4.php" file below is mainly in HTML, and PHP syntax is only used in the variable output part;

<!-- 4 - user-info-4.php -->
<p>name: <?php echo $name; ?></p>
<p>blog: <?php echo $blog; ?></p>
<p>afdian: <?php echo $afdian; ?></p>

In a sense, the code and mechanism represented by the three comments // Data for display - index.php, // Four - index.php, and <!-- 4 - user-info-4.php --> constitute a simple template syntax implementation;

However, inserting PHP syntax into HTML is still not very convenient, and in fact, the code in the <!-- 4 - user-info-4.php --> part is converted from the following code:

 <!-- 4 - user-info-4.php -->
<p>name: {$name}</p>
<p>blog: {$blog}</p>
<p>afdian: {$afdian}</p>

↑ This is also the "template tag" syntax adopted by Z-BlogPHP;

Reference:
"Theme Development - Z-BlogPHP Documentation"
"Template Tags - Theme Development - Z-BlogPHP Documentation"
;

Attachment Download#

Link: https://pan.baidu.com/s/19wH0sg5mXnY50Gue4ordlw

Extract code: 4gaa

It contains two compressed packages, one is the code directly involved in this tutorial (unencrypted), and the other contains the condensed and extracted Z-BlogPHP Template class and annotations (encrypted);

The password acquisition scheme is as follows:

"- -", "- -", "- -"

"Tinkering" Z-BlogPHP Template Mechanism Explanation 丨 Sinking Ice and Floating Water 丨 Afdian:

[https://afdian.net/p/5e8460cefdbc11eb80a152540025c377](https://afdian.net/p/5e8460cefdbc11eb80a152540025c377 "Tinkering" Z-BlogPHP Template Mechanism Explanation 丨 Sinking Ice and Floating Water 丨 Afdian)

↑ Optional amount should be able to unlock it;

"- -", "- -", "- -"

Follow WeChat Official Account: "Water Water Doesn't Want to Speak";

Send the password... No, actually you don't need to send anything, you don't even need to follow this official account, there is no password here;

"- -", "- -", "- -"

Subscribe to this blog using RSS;

[ShortSth

][/ShortSth]

The password is divided into two parts, in the format of "php-tpl-xxxx", with a total length of 8 digits - "1****e****";

["Speaking" RSS is an attitude!!_Miscellaneous_Sinking Ice and Floating Water](https://www.wdssmq.com/post/20201231613.html ""Speaking" RSS is an attitude!!_Miscellaneous_Sinking Ice and Floating Water")

["Annual Routine" Z-Blog applications under the name of Water Water_Miscellaneous_Sinking Ice and Floating Water](https://www.wdssmq.com/post/20120926864.html ""Annual Routine" Z-Blog applications under the name of Water Water_Miscellaneous_Sinking Ice and Floating Water")

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.