Page 1 of 1

How can I add an INCLUDE into Viewforum_body using Forum_ID

Posted: Mon Aug 25, 2014 8:41 am
by gussie
I've searched the forum for a solution that might address my problem but haven't yet seen something that could help me (I'll keep looking). I did find this article in the KB, and I wonder if it could be adapted for my purpose: https://www.phpbb.com/kb/article/howto- ... ch-in-acp/

My goal
I would like to add some simple HTML to some of the forums on my site. These would be jumping off points (links), maybe some forum-specific sponsorship (ad code), maybe some additional media (embeded iFrame). Not all of my forums would need this - but there's always the chance a future moderator would identify a purpose to add something. The most obvious use are links to popular topics or keyword searches within a particular forum.

My original idea
What I would like to do is simply <!-- INCLUDE --> a file that has that particular forum's extra content. So, I thought about naming the extra content file /extracontent/{FORUM_ID}.txt -- then in the viewforum_body.html template, I would use
<!-- IF file_exists(/path/to/extracontent/{FORUM_ID}.txt) --><!-- INCLUDE path/to/extracontent/{FORUM_ID}.txt --><!-- ENDIF -->

I tried doing this by following the example on how to use file_exists over here http://php.net/manual/en/function.file-exists.php - I tried to load the /extracontent/{FORUM_ID}.txt into a variable ({EXTRACONTENTLOCATION}) so I could use it this way:

In the viewforum.php file

Code: Select all

$extracontentlocation = /path/to/extracontent/{FORUM_ID}.txt;
<!-- IF file_exists($extracontentlocation) -->
$s_extracontentlocation = true;
<!-- ELSE -->
$s_extracontentlocation = false;
<!-- ENDIF -->

...

'S_EXTRACONTENTLOCATION' = $s_extracontentlocation,
'EXTRACONTENTLOCATION' = $extracontentlocation,
... then, in the viewforum_body.html template

Code: Select all

<!-- IF {S_EXTRACONTENTLOCATION} --><!-- INCLUDE {EXTRACONTENTLOCATION} --><!-- ENDIF -->

This hasn't worked. It blanks out my viewforum.php page when I call it up.

Alternate methods?
In addition to the KB method above, I might try to copy the way the Forum Rules box is used. This is essentially what I want to do - some forums have forum rules and others do not show any, and all of this (text only?) seems to be stored it the SQL, instead of as HTML files to be INCLUDED in the template.

I like my method because it did not require any changes to the SQL.

Any ideas?

This idea is related to what I learned in the Topic Description mod and what I learned from adapting it to my forum:
viewtopic.php?f=71&t=2258406
https://www.phpbb.com/customise/db/mod/ ... 36#p376036

Re: How can I add an INCLUDE into Viewforum_body using Forum

Posted: Mon Aug 25, 2014 10:45 am
by RMcGirr83

Code: Select all

<!-- IF S_EXTRACONTENTLOCATION --><!-- INCLUDE {EXTRACONTENTLOCATION} --><!-- ENDIF -->

Re: How can I add an INCLUDE into Viewforum_body using Forum

Posted: Mon Aug 25, 2014 12:19 pm
by Brf
gussie wrote:

Code: Select all

$extracontentlocation = /path/to/extracontent/{FORUM_ID}.txt;
<!-- IF file_exists($extracontentlocation) -->
$s_extracontentlocation = true;
<!-- ELSE -->
$s_extracontentlocation = false;
<!-- ENDIF -->
Three problems.
1. Strings need to be enclosed in "quotes"

2. {FORUM_ID} is not a phpBB variable. You should be using $forum_id

3. IFs do not work that way in PHP. You should be using

Code: Select all

if condition
{
do something
} else {
do something else
}

Re: How can I add an INCLUDE into Viewforum_body using Forum

Posted: Tue Aug 26, 2014 2:15 pm
by gussie
Brf wrote:
gussie wrote:

Code: Select all

$extracontentlocation = /path/to/extracontent/{FORUM_ID}.txt;
<!-- IF file_exists($extracontentlocation) -->
$s_extracontentlocation = true;
<!-- ELSE -->
$s_extracontentlocation = false;
<!-- ENDIF -->
Three problems.
1. Strings need to be enclosed in "quotes"

2. {FORUM_ID} is not a phpBB variable. You should be using $forum_id

3. IFs do not work that way in PHP. You should be using

Code: Select all

if condition
{
do something
} else {
do something else
}
You are correct. The syntax I used is for templates. I do have that conditional written in the way you describe - $topic_forum_id and with the curley brackets - in my viewforum.php file but it doesn't seem to load my variable with the boolean values. When I try to display the variables in the template, they are blank.

Code: Select all

$extracontentlocation = '/path/to/extracontent/' . $topic_forum_id . '.txt';

if (file_exists($extracontentlocation)) {
$s_extracontentlocation = true;
} else {
$s_extracontentlocation = false;
}
And then in my viewforum_body.html template, I use something like this:
RMcGirr83 wrote:

Code: Select all

<!-- IF S_EXTRACONTENTLOCATION --><!-- INCLUDE {EXTRACONTENTLOCATION} --><!-- ENDIF -->
I was so hoping this was going to work. It doesn't in mine. I also try to print out the switch variable as {S_EXTRACONTENTLOCATION} but it is blank

Re: How can I add an INCLUDE into Viewforum_body using Forum

Posted: Tue Aug 26, 2014 3:16 pm
by Brf
Brf wrote: $forum_id
gussie wrote:$topic_forum_id

Re: How can I add an INCLUDE into Viewforum_body using Forum

Posted: Tue Aug 26, 2014 3:19 pm
by gussie
Brf wrote:
Brf wrote: $forum_id
gussie wrote:$topic_forum_id
Yes - $topic_forum_id is what is used in viewforum.php

Re: How can I add an INCLUDE into Viewforum_body using Forum

Posted: Tue Aug 26, 2014 3:25 pm
by Brf
Either variable works inside the topicrow loop. Is that where you put your code? If so, you would be generating {topicrow.S_EXTRACONTENTLOCATION} inside of the topicrow loop.

Re: How can I add an INCLUDE into Viewforum_body using Forum

Posted: Tue Aug 26, 2014 3:29 pm
by gussie
Thank you for clarifying that. No, I was not using those variables in the loop. I guess that's where my error is

I thought I could use a variable that identified the forum so that if I have an extracontent.txt file for that particular forum, I could show it above or below the topic listing table.

Can you tell me what variable I should use? I'll go over the phpbb wiki - I think there is a variable list there

Re: How can I add an INCLUDE into Viewforum_body using Forum

Posted: Tue Aug 26, 2014 3:34 pm
by Brf
Brf wrote:
Brf wrote: $forum_id

Re: How can I add an INCLUDE into Viewforum_body using Forum

Posted: Tue Aug 26, 2014 4:34 pm
by gussie
Thank you. It works now.

Here is what I did wrong:

1. I was loading the S_EXTRACONTENTLOCATION and EXTRACONTENTLOCATION variables in the wrong location -- they should have been higher up in the viewforum.php file, but I was loading them down in the topicrow area.

2. I forgot that referencing the file at EXTRACONTENTLOCATION will differ between viewforum.php and viewforum_body.html - so I need to make sure that when I load EXTRACONTENTLOCATION for use in the template, I must add ../../../

Here is the code in viewforum.php that works for me:

Code: Select all

$extracontentlocation = 'path/from/viewforum.php/to/' . $forum_id . '.html';

if (file_exists($extracontentlocation)) {
	$s_extracontentlocation = true;
} else {
	$s_extracontentlocation = false;
}	

$template->assign_vars(array(
    'MODERATORS'    => (!empty($moderators[$forum_id])) ? implode(', ', $moderators[$forum_id]) : '',

	    'S_EXTRACONTENTLOCATION'   => $s_extracontentlocation,
	    'EXTRACONTENTLOCATION'   => '../../../' . $extracontentlocation,
In viewforum_body.html, I simply use the code that RMcGirr83 provided

Thank you both for your help!