How can I <!-- INCLUDE --> a filename from a variable?

Discussion forum for MOD Writers regarding MOD Development.
Locked
User avatar
gussie
Registered User
Posts: 92
Joined: Wed Nov 27, 2002 1:26 am

How can I <!-- INCLUDE --> a filename from a variable?

Post by gussie »

I would like to insert some html code in certain topics of my forum, and I thought about using INCLUDE to identify html files on my server.

Say I store the file name in a variable - like {ExtraText} - so that topics that I choose that pull in the contents of /path/to/{ExtraText}.html

I tried adding the {ExtraText} variable inside the <!-- INCLUDE --> code, but it was ignored (parsed away?)

Can you suggest another way I can reference those html files?
Res tantum valet quantum vendi potest
Do not hire Christian Bullock - he will not finish the job and he will not return your money.
User avatar
AmigoJack
Registered User
Posts: 6108
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: How can I <!-- INCLUDE --> a filename from a variable?

Post by AmigoJack »

Code: Select all

preg_match_all('#<!-- INCLUDE (\{\$?[A-Z0-9\-_]+\}|[a-zA-Z0-9\_\-\+\./]+) -->#', $code, $matches);
Template variables must be in uppercase, make it {EXTRATEXT}.
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
gussie
Registered User
Posts: 92
Joined: Wed Nov 27, 2002 1:26 am

Re: How can I <!-- INCLUDE --> a filename from a variable?

Post by gussie »

Thank you!

I was trying to add the <!-- INCLUDE ... --> code in the viewtopic_body.html template

Should I add the code that you suggest in the viewtopic.php file?
I guess what I would like to do is add <!-- INCLUDE /path/to/ and --> around {EXTRATEXT} - so do I load 'EXTRATEXT' like this

Code: Select all

'EXTRATEXT'    => preg_match_all('#<!-- INCLUDE (\{\$?[A-Z0-9\-_]+\}|[a-zA-Z0-9\_\-\+\./]+) -->#', $code, $matches);
How do I write this properly? Please help me understand how I should treat $code and $matches
Last edited by gussie on Thu Aug 21, 2014 3:00 am, edited 1 time in total.
Res tantum valet quantum vendi potest
Do not hire Christian Bullock - he will not finish the job and he will not return your money.
User avatar
gussie
Registered User
Posts: 92
Joined: Wed Nov 27, 2002 1:26 am

Re: How can I <!-- INCLUDE --> a filename from a variable?

Post by gussie »

I tried to add this line in viewtopic.php just above // Send vars to template

Code: Select all

preg_match_all('#<!-- INCLUDE (\{\$?[A-Z0-9\-_]+\}|[a-zA-Z0-9\_\-\+\./]+) -->#', '<!-- INCLUDE path/to/' . $topic_data['extra_text'] . '.html -->', $extratextcode, $matches);
Then in the // Send vars to template section, I add 'EXTRA_TEXT_INCLUDE' => $extratextcode,




In the viewtopic_body.html, I add {EXTRA_TEXT_INCLUDE} but the output is the word "Array" instead of the contents of the filename



In viewtopic.php, I also try using 'EXTRA_TEXT_INCLUDE' => $extratextcode[0], or 'EXTRA_TEXT_INCLUDE' => $extratextcode[1], but the output is still the same, the word "Array"
Res tantum valet quantum vendi potest
Do not hire Christian Bullock - he will not finish the job and he will not return your money.
User avatar
AmigoJack
Registered User
Posts: 6108
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: How can I <!-- INCLUDE --> a filename from a variable?

Post by AmigoJack »

gussie wrote:Should I add the code that you suggest in the viewtopic.php file?
No, it's the part that renders the template INCLUDE instruction, hence I didn't add any file and position where to add this. From the code you can see that INCLUDE either accepts variables ({VARIABLE}) or filenames (/to/file.html), but no mixture. If you want to mix it, then do it where you assign VARIABLE already.
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
gussie
Registered User
Posts: 92
Joined: Wed Nov 27, 2002 1:26 am

Re: How can I <!-- INCLUDE --> a filename from a variable?

Post by gussie »

AmigoJack wrote:
gussie wrote:Should I add the code that you suggest in the viewtopic.php file?
No, it's the part that renders the template INCLUDE instruction, hence I didn't add any file and position where to add this. From the code you can see that INCLUDE either accepts variables ({VARIABLE}) or filenames (/to/file.html), but no mixture. If you want to mix it, then do it where you assign VARIABLE already.
Thank you for checking back in here, AmigoJack!

When you say it is the part that renders the instruction, then, in my case, you are talking about the spot in the viewtopic_body.html template where I want the HTML code in /to/file.html to be shown in the viewtopic page.

So, instead of using the code:

Code: Select all

<!-- INCLUDE /to/file.html -->
I should use the code:

Code: Select all

preg_match_all('#<!-- INCLUDE (\{\$?[A-Z0-9\-_]+\}|[a-zA-Z0-9\_\-\+\./]+) -->#', $code, $matches);
in the viewtopic_body.html template

I do not see where I should put /to/file.html - should I put it in place of #code or #matches? Or is it supposed to go between the # signs?
Res tantum valet quantum vendi potest
Do not hire Christian Bullock - he will not finish the job and he will not return your money.
User avatar
AmigoJack
Registered User
Posts: 6108
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: How can I <!-- INCLUDE --> a filename from a variable?

Post by AmigoJack »

No, forget it all.

Open /styles/*/template/*.html and add either

Code: Select all

<!-- INCLUDE file.html -->
or

Code: Select all

<!-- INCLUDE {MY_FILE} -->
You have to decide upon one of both forms, you can't combine them.
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
Lumpy Burgertushie
Registered User
Posts: 69223
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: How can I <!-- INCLUDE --> a filename from a variable?

Post by Lumpy Burgertushie »

no, you don't put php in the html file.

the point is that the php file is where you have to create whatever variable you are wanting to use.

I have no idea what you are trying to accomplish but it doesn't matter.

you create the variable with php , you put that new php code in the relevant php file.

once the variable is created, you can then use that variable in a html file.

however, from what it looks like you are doing you can just include whatever html file you wish inside whatever html file you are working with . doing that does not require a new variable.

for instance, in index_body.html you will find this:

Code: Select all

<!-- INCLUDE overall_header.html -->
if you have a html file that you wish to include in another html file then just do the same thing.

assuming , of course, that you are working with phpbb files to begin with.

robert
Premium phpBB 3.3 Styles by PlanetStyles.net

I am pleased to announce that I have completed the first item on my bucket list. I have the bucket.
User avatar
gussie
Registered User
Posts: 92
Joined: Wed Nov 27, 2002 1:26 am

Re: How can I <!-- INCLUDE --> a filename from a variable?

Post by gussie »

Lumpy Burgertushie wrote:no, you don't put php in the html file.

the point is that the php file is where you have to create whatever variable you are wanting to use.

I have no idea what you are trying to accomplish but it doesn't matter.

you create the variable with php , you put that new php code in the relevant php file.

once the variable is created, you can then use that variable in a html file.
Yes! That's my understanding as well. This is why AmigoJack's original line of code didn't make sense to me. I assumed it would go into the php file
Lumpy Burgertushie wrote:if you have a html file that you wish to include in another html file then just do the same thing.
Yeah, and that is NOT what I am trying to do. That much I do know.
AmigoJack wrote:Open /styles/*/template/*.html and add either

Code: Select all

<!-- INCLUDE file.html -->
or

Code: Select all

<!-- INCLUDE {MY_FILE} -->
You have to decide upon one of both forms, you can't combine them.
Right - that much I already know.

Here's what I was trying to explain:

Say I have a text file that I want to INCLUDE into some, but not all, topics - let's call that file embededcontent.txt

I want to include it in topic A and topic B, but not topic C or topic D. If I wanted it in all topics, I simply INCLUDE embededcontent.txt

I have a switch variable that tells my phpBB whether or not to include it in a topic - let's call that variable {JUST_DO_IT} and the contents of that variable would be the word, "embededcontent"

So: If {JUST_DO_IT}, then <!--INCLUDE {JUST_DO_IT}.txt -->
else don't include anything. This way, I just make sure topic A and topic B have the word "embededcontent" and the other topics stay blank.


Since it wasn't clear to me whether to use AmigoJack's line in a template, I assumed he or she must have meant to use it in the php file - because preg_match_all is a function call. But, then, the question is: how? And how to use the output parameter ($code) and the pattern match parameter ($matches) - not to mention where to specify my file name variable {JUST_DO_IT}


What is this for? Sometimes, in certain topics on my forum (maybe the most popular or controversial at any given moment), our admins or moderators would like to add a note that would appear at the bottom of every page of a topic. This note could be a map plus directions, it could be an affiliate code banner, it could be some official warning or explanation. This would only happen in certain special situations, so it doesn't apply to most topics.

The bonus in using a file name (like embededcontent.txt) as the switch is it allows us to re-use that content in other topics at a later time.
Res tantum valet quantum vendi potest
Do not hire Christian Bullock - he will not finish the job and he will not return your money.
User avatar
Lumpy Burgertushie
Registered User
Posts: 69223
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: How can I <!-- INCLUDE --> a filename from a variable?

Post by Lumpy Burgertushie »

why not create one or more custom bbcodes and not show them on the posting page. your mods/admins would know what they are and could post whatever this extra text is at will in any post on the board.


robert
Premium phpBB 3.3 Styles by PlanetStyles.net

I am pleased to announce that I have completed the first item on my bucket list. I have the bucket.
User avatar
gussie
Registered User
Posts: 92
Joined: Wed Nov 27, 2002 1:26 am

Re: How can I <!-- INCLUDE --> a filename from a variable?

Post by gussie »

Lumpy Burgertushie wrote:why not create one or more custom bbcodes and not show them on the posting page. your mods/admins would know what they are and could post whatever this extra text is at will in any post on the board.
Because it would have to be in a post, and that post would not appear conveniently at the bottom (or wherever) of every page of the topic thread.

We have a few restaurant forums, and this suggestion was originally proposed to me by one of our restaurant moderators. There would be long discussions about a restaurant, and he realized that for many readers, after reading part of a topic, they would want to know some basic and obvious information, like: how do I find this amazing restaurant that everyone is talking about

Btw, I have recently started trying out BroadStreetAds.com, which offers a few different ad server formats for hyperlocal communities. It's intended specifically for Wordpress blogs. But I can see how having topic-specific zones (as opposed to forum specific) would work for Broadstreet Ads's Selfie and EditableAds services - because they would be linked to the ad server via the topic ID the way blog posts are linked by post ID. Some of the most useful topics in my forum are recommendations and warnings about local services.

More recently, in a different forum on the site, a recommendation for some novel writing software was posted. All of a sudden, a bunch of other members piled in to share their great experiences with that software. I had never heard of it before, and a quick online search not only brought me the software writer's page, but eventually connected me to that person's affiliate program. I sent him a link to the topic about his writing software on my site and he wrote me back to approve use of his affiliate link. What would be cool about adding that affiliate code into a file is that should a new discussion pop up later on or in a different forum, someone on the moderating team can add the affiliate code to the new topic by specifying the emdedcontent.txt of that affiliate code. I wouldn't expect the topic to come up as often enough to justify hidden BBcode
Last edited by gussie on Thu Aug 21, 2014 8:45 am, edited 1 time in total.
Res tantum valet quantum vendi potest
Do not hire Christian Bullock - he will not finish the job and he will not return your money.
User avatar
AmigoJack
Registered User
Posts: 6108
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: How can I <!-- INCLUDE --> a filename from a variable?

Post by AmigoJack »

gussie wrote:If {JUST_DO_IT}, then <!--INCLUDE {JUST_DO_IT}.txt -->
That would be

Code: Select all

<!-- IF {JUST_DO_IT} --><!-- INCLUDE {JUST_DO_IT} --><!-- ENDIF -->
gussie wrote:some official warning or explanation
That's what post edit reasons are for.
gussie wrote:Since it wasn't clear to me whether to use AmigoJack's line in a template, I assumed he or she must have meant to use it in the php file - because preg_match_all is a function call
Since it was PHP code it was meant to be in a PHP file, of course. But not to be inserted or used by you. And since {JUST_DO_IT} does not appear by will I assumed you already know where to define this - was I wrong?
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
gussie
Registered User
Posts: 92
Joined: Wed Nov 27, 2002 1:26 am

Re: How can I <!-- INCLUDE --> a filename from a variable?

Post by gussie »

AmigoJack wrote:
gussie wrote:If {JUST_DO_IT}, then <!--INCLUDE {JUST_DO_IT}.txt -->
That would be

Code: Select all

<!-- IF {JUST_DO_IT} --><!-- INCLUDE {JUST_DO_IT} --><!-- ENDIF -->
Thank you! I'll give that a shot
AmigoJack wrote:
gussie wrote:some official warning or explanation
That's what post edit reasons are for.
Right, but we have encountered situations where we might want to place special messages on every page of the topic for special situations. To wit, earlier this month, in a thread about a religious group, links were being posted to external websites (not ours) that warned people about a particular group. That group actually contacted us and hinted legal action - not about stuff on our forums, but on stuff on those blogs. We are based in a country where a libel suit, no matter how ultimately spurious, can be easily and inexpensively initiated. Posting a simple reminder (stating the obvious notion that stuff that is not on our website is, well, not our responsibility - heck, we even disclaim stuff on our own website!) mollified the religious group in question. We would not necessarily want that reminder on every page of the site, but posting it on every page of a long discussion is a nice touch.

I actually did make hidden BBcode for our moderators to post that reminder in a post. But that became tedious (the silliness of disclaiming links on a forum was more apparent) and in itself became controversial - some readers questioned why some links were marked by the disclaimer and others not. So, adding it to the bottom of the topic suddenly became more useful.
AmigoJack wrote:
gussie wrote:Since it wasn't clear to me whether to use AmigoJack's line in a template, I assumed he or she must have meant to use it in the php file - because preg_match_all is a function call
Since it was PHP code it was meant to be in a PHP file, of course. But not to be inserted or used by you. And since {JUST_DO_IT} does not appear by will I assumed you already know where to define this - was I wrong?
I guess you were mistaken to assume a deeper understanding of modifying the PHP files on my part, and I'm sorry for that. I'm still a bit hazy on what you mean by the preg_match_all function "not to be inserted or used by you", because I think we agree that I was expected to insert or use it in the PHP file somewhere. I ended up trying to insert it just before the variables are set up in the PHP file, but I didn't know how to relate {JUST_DO_IT} to that code snippet.

I will give your earlier IF / ENDIF suggestion a shot. I think that's what I was looking for, because I can easily store the entire filename "embededcontent.txt" in {JUST_DO_IT} instead of simply the word "embededcontent" -- THANK YOU! Image
Res tantum valet quantum vendi potest
Do not hire Christian Bullock - he will not finish the job and he will not return your money.
User avatar
gussie
Registered User
Posts: 92
Joined: Wed Nov 27, 2002 1:26 am

Re: How can I <!-- INCLUDE --> a filename from a variable?

Post by gussie »

AmigoJack wrote:
gussie wrote:If {JUST_DO_IT}, then <!--INCLUDE {JUST_DO_IT}.txt -->
That would be

Code: Select all

<!-- IF {JUST_DO_IT} --><!-- INCLUDE {JUST_DO_IT} --><!-- ENDIF -->
That worked!!!

Thank you :)

I was over-complicating it by not including the /path/to/the/file and the file extension. By putting the whole path and filename in as the switch, it worked without a hitch
Res tantum valet quantum vendi potest
Do not hire Christian Bullock - he will not finish the job and he will not return your money.
Locked

Return to “[3.0.x] MOD Writers Discussion”