Dependencies with templates

My CMS has an index page intermixed with alternate syntax and a lot of HTML markup sandwiched between gooey scripts.
But one of the templates I’m using to write a similar class of files, should include the index page to fill up placeholders before the file write. However, because of all that markup on the index, every include automatically forces them onto the template as well. Is there a way I could glean the code which I need during the include and render only required php or must I place the code in a separate file?(This option hampers readability, accessibility and truncates my entire software architecture)

Sorry, but your question makes no sense whatsoever to me personally. Can you try to explain your problem again? Maybe show some example code? Can you explain how a template is related to a class of files? What is a class of files? How does an index page fill up placeholders in a template? What template system are you using?

Scott

What CMS is it? Each tend to have a different workflow.

It’s a custom made CMS I am building from the scratch that does a lot of stuff amongst which include writing some dynamic files which are similar to one another(class of files)

However, the files are written following a pattern (a template I wrote) and the template depends on the current index page doing the file write for certain variables (circular dependency).

Problem is, including the index file in the template causes the index’s markup to spill into the template as well.
It’s a framework of some sort I might release later.

If no one understands, never mind. I’ll just stick to the idea I had while opening the thread which was to abstract the code from client side stuff and refactor the software architecture.

As odd as it may seem, while some may have some difficulty understanding something expressed in English. most will understand code much more easily.

If you can post a link to a public repository, a CodePen (or similar), relevant code snippets, or an attachment, I think you will find that the language of Code is more universally understood here.

1 Like

Yes. I do feel the same way sometimes as one can interpret and capture what code does better than its author could express in lay terms. But due to the nature of the project, I might be indisposed to posting actual code samples (Hope that does not offend you). I’ll use placeholders:
index.php

<!--html forms similar to below markup here; all accepting input from administrator but form action is an empty string-->
<?php
$content = $_GET ['content'];
$title = $_GET ['title'];

file_put_contents ("../" . $_SERVER['DOCUMENT_ROOT'] . "/$title/index.php", file_get_contents ("../new_docs/template.php));
?>
<!--form regarding above PHP script goes here. Other HTML markup follows with their respective PHP scripts-->

Then new_docs/template.php

<?php
include "../index.php";
?>
<!Doctype html>
<html>
<title> <?php echo $title; ?> </title >
<body> <?php echo $content; ?> </body>
</html>

I’m trying to grok the logic. So I’m probably missing something(s)

The mark-up from template.php is being written to the index.php file in the folder with the name taken from the GET title variable.
Then that mark-up is being prepended to the skeleton HTML page.
The title tag’s content comes from the GET title variable.
The body tag’s content comes from the GET content variable.

Two things seem off to me.
Should mark-up be getting prepended before <!Doctype html> ?
Isn’t everything inside body a bit much to be passing around as a GET ?

Sorry @nmeri17. I don’t mean to be rude, but I personally can’t help you with what you have offered. The code makes just a little sense as your explanations, unfortunately.

If I may ask, how long have you been programming in PHP?

Scott

1 Like

Hey guys! I finally figured out how to go about it. I first wrote to a log file, then had the template read from that file (containing only the variables I need). Something like an intermediary or mediator between the dreaded markup and what I need. So to modify what I posted earlier, I have the following in my index.php

<!--html forms similar to below markup here; all accepting input from administrator but form action is an empty string-->
<?php
$title = 'go';
$body = "here";
$date = "now";
$name = "raheem";

$log = '<?php
$article_title = '. $title . ';' . "\n" . '$body = ' . $body . ';' . "\n" . '$name = ' . $name . ';' . "\n" . '$date = ' . $date . ';' . "\n?>";
file_put_contents("../new_doc/log.php", $log);
file_put_contents($title . "/index.php", file_get_contents("/new_doc/template.php"));
?>
<!--form regarding above PHP script goes here. Other HTML markup follows with their respective PHP scripts-->

Then /new_doc/template.php now contains

<?php
include "log.php";
?>
<!DOCTYPE html>
<html>
<title> <?php echo $title; ?> </title>
<body>
<?php echo $body; ?>
<aside><?php echo $name . $date; ?> </aside>
</body>
</html>

But thanks for trying to help.

Just yesterday evening bro :cry:

Why do your want to use a template engine already ?
And what are you doing with your cms ?
Use it for clients or throw it away ?

Writing a file to the file system every request is not the way to do that.

Hey guys! I eventually tried what I had in my mind but it didn’t quite work out as expected. The template engine does not grab the variables from the sign up page to use in creating its own file. I have a static class on the member template that looks like this

Then in the sign up script, during the file write, I have something like this

$replace_arr = array('require_once sign_up.php',
'this loop should check where the array for where the new object matches, fetch that object then store it in the instance static variable');
$static_file = str_replace($replace_arr, '',
file_get_contents("member.php"));
$pagename = str_replace('_', '.', $username);
$user_doc = file_force_contents($_SERVER
["DOCUMENT_ROOT"]."/$pagename/index.php",
$static_file);

But it just copies all the contents of the member template into the new file. Please does anyone know how I should go about it?? :sad:

OK. Be kind enough to tell me the correct way to go about it.

I explicitly set the username global var on the admin panel and it works perfectly so all I need is for the page to catch that username from sign up before its file write

I wonder what’s this guy’s programming background. It’s apparently not PHP, but I fail to recognize any other source. The coding patterns are too… eclectic.

[quote=“colshrapnel, post:17, topic:220571”]
The coding patterns are too… eclectic.
[/quote]https://en.m.wiktionary.org/wiki/eclectic
I’ll take that as a compliment :slight_smile:

Why can’t you just use a template engine that someone has already written?

I need xdebug to step through your code to even make the slightest sense what you’re trying to do.

2 Likes

LOL Don’t worry guys :smiley: :smiley: I’m home and dry. I’ve fixed everything and signed myself up. Thanks once again for trying to help. Y’all are the best!!

I used constants though and they gave me what I want.