Open KogucikPL opened 1 month ago
I solved the problem using simple php, more specifically:
<?php
$jsonFile = 'path/to/file.json';
$jsonData = file_get_contents($jsonFile);
$dataArray = json_decode($jsonData, true);
function replacePlaceholders($template, $dataArray) {
foreach ($dataArray as $data) {
$order = $data['order'];
foreach ($data as $key => $value) {
$placeholder = "{{{$key}{$order}}}";
if (strpos($template, $placeholder) !== false) {
$template = str_replace($placeholder, $value, $template);
}
}
}
return $template;
}
ob_start();
?>
<!-- Some HTML code -->
<div class="plyr-player">
<video class="plyyr" playsinline controls data-poster="/assets/video/{{folder100}}/thumb.png" data-thumbnail-src="/assets/video/{{folder100}}/preview.vtt">
<source src="/assets/video/{{folder100}}/1080p.mp4" type="video/mp4" size="1080" />
<source src="/assets/video/{{folder100}}/720p.mp4" type="video/mp4" size="720" />
<source src="/assets/video/{{folder100}}/480p.mp4" type="video/mp4" size="480" />
<source src="/assets/video/{{folder100}}/360p.mp4" type="video/mp4" size="360" />
</video>
</div>
<!-- Some HTML code -->
<?php
$htmlContent = ob_get_clean();
$replacedContent = replacePlaceholders($htmlContent, $dataArray);
echo $replacedContent;
?>
Maybe it will be useful to someone in the future. I thank myself for helping lol
I have a script that replaces placeholders with the corresponding values from a JSON array. In general, the replacement works fine everywhere, but for some reason it doesn't want to work with these attributes. For example:
gives
Expected behaviour:
I would like
<video class="plyyr" playsinline controls data-poster="/assets/video/{{folder}}/thumb.png" data-thumbnail-src="/assets/video/{{folder}}/preview.vtt">
to change to<video class="plyyr" playsinline controls data-poster="/assets/video/book/thumb.png" data-thumbnail-src="/assets/video/book/preview.vtt">
and then work as "intended", i.e. add a video poster and display thumbnails in the progress bar.Actual behaviour:
Currently the replacement works. The console and browser see the change. Theoretically, the placeholders change, but despite this, neither the poster nor the preview works. When it comes to lines like this one, after replacing everything works:
<source src="/assets/video/{{folder}}/1080p.mp4" type="video/mp4" size="1080" />
When I replace the placeholder manually (i.e. I simply enter the path myself), then everything works perfectly, but with the placeholder it does not want to work, even though the browser and console see the change correctly.Steps to reproduce:
Environment:
Console errors (if any):
None.
Thank you in advance for any help.