added variables in create_html with compact
This commit is contained in:
@@ -43,10 +43,21 @@ function main_shortcode() {
|
|||||||
"myvar_2",
|
"myvar_2",
|
||||||
));
|
));
|
||||||
|
|
||||||
return create_html( array(
|
|
||||||
|
$names = ["hugo", "camille"];
|
||||||
|
$ages = ["13", "34", "56"];
|
||||||
|
$html_front = create_html(
|
||||||
|
array(
|
||||||
"index.html",
|
"index.html",
|
||||||
"index2.html",
|
"index2.html",
|
||||||
));
|
),
|
||||||
|
compact(
|
||||||
|
"names",
|
||||||
|
"ages",
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return $html_front;
|
||||||
}
|
}
|
||||||
add_shortcode('fipf_wp_plugin', 'main_shortcode');
|
add_shortcode('fipf_wp_plugin', 'main_shortcode');
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<p>i am a new p</p>
|
<p>i am a new p</p>
|
||||||
|
<p class="first_el_to_change">to change</p>
|
||||||
<?php
|
<?php
|
||||||
foreach($names as $name) {
|
foreach($names as $name) {
|
||||||
include($template_dir."presentation.html");
|
include($template_dir."presentation.html");
|
||||||
|
|||||||
@@ -1 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
foreach($ages as $age) {
|
||||||
|
?>
|
||||||
|
<p>age <?php echo esc_html($age); ?></p>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<p class="third_el_to_change">to change</p>
|
||||||
<p>aaaaaand this is the end</p>
|
<p>aaaaaand this is the end</p>
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
<p>hello <?php echo esc_html($name); ?></p>
|
<p>hello <?php echo esc_html($name); ?></p>
|
||||||
|
<p class="second_el_to_change">to change</p>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
const title = document.querySelector(".has-text-align-center.wp-block-post-title");
|
const title = document.querySelector(".first_el_to_change");
|
||||||
title.innerHTML = "coucou ;)";
|
title.innerHTML = "--- coucou ;)";
|
||||||
|
|
||||||
console.log("myvar_1: " + myvar_1);
|
console.log("myvar_1: " + myvar_1);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
|
|
||||||
const title2 = document.querySelector(".wp-block-quote");
|
const title2 = document.querySelector(".second_el_to_change");
|
||||||
title2.innerHTML = "ho boy !";
|
title2.innerHTML = "--- ho boy !";
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
const title3 = document.querySelector(".has-text-align-center.wp-block-post-title");
|
const title3 = document.querySelector(".third_el_to_change");
|
||||||
title3.innerHTML = "bye bye";
|
title3.innerHTML = "--- bye bye";
|
||||||
console.log("myvar_2: " + myvar_2);
|
console.log("myvar_2: " + myvar_2);
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
.has-text-align-center.wp-block-post-title {
|
.first_el_to_change {
|
||||||
border: 1px solid red;
|
border: 1px solid red;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,13 @@
|
|||||||
#
|
#
|
||||||
# https://stackoverflow.com/a/4402045/9497573
|
# https://stackoverflow.com/a/4402045/9497573
|
||||||
|
|
||||||
function create_html($files) {
|
# takes two arguments :
|
||||||
|
# a list of the html files to include in front
|
||||||
|
# a list of variables to make available to this files
|
||||||
|
function create_html($files, $vars) {
|
||||||
$html_dir = plugin_dir_path(__DIR__).'html/';
|
$html_dir = plugin_dir_path(__DIR__).'html/';
|
||||||
$template_dir = plugin_dir_path(__DIR__).'html/templates/';
|
$template_dir = plugin_dir_path(__DIR__).'html/templates/';
|
||||||
|
extract($vars);
|
||||||
$names = ["hugo", "camille"];
|
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
foreach($files as $file) {
|
foreach($files as $file) {
|
||||||
|
|||||||
Reference in New Issue
Block a user