Passing constants to an html file

Discussion forum for MOD Writers regarding MOD Development.
Locked
User avatar
RMcGirr83
Former Team Member
Posts: 21593
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Passing constants to an html file

Post by RMcGirr83 »

Is it possible?

For example, let's say I have defined a constant in an external file

Code: Select all

define('blah_blah_blah',1);
can i use that in a html file?

eg

Code: Select all

<!-- IF whatever == blah_blah_blah -->true<!-- ENDIF -->
:?

TIA as always :)
Appreciate the extensions/mods/support then buy me a beerImage
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
User avatar
Nelsaidi
Registered User
Posts: 525
Joined: Mon Feb 11, 2008 1:59 pm
Location: London, UK
Contact:

Re: Passing constants to an html file

Post by Nelsaidi »

In HTML or PHPBB3 Template?

Passing it to a HTML template wont be possible (atleast not very easily) - PHPBB3 is possible i believe, bbut i suck at templates system
Image
Click here to find out what eRepublik is.
User avatar
RMcGirr83
Former Team Member
Posts: 21593
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Passing constants to an html file

Post by RMcGirr83 »

Sorry, meant to a phpBB3 html file
Appreciate the extensions/mods/support then buy me a beerImage
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52127
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Passing constants to an html file

Post by Brf »

I would think that if you defined a constant like that, it should work... assuming the template parser will let that through. I would guess that it might assume that constant was a template loop variable and attempt to parse it like that.
User avatar
RMcGirr83
Former Team Member
Posts: 21593
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Passing constants to an html file

Post by RMcGirr83 »

Brf wrote:I would think that if you defined a constant like that, it should work... assuming the template parser will let that through. I would guess that it might assume that constant was a template loop variable and attempt to parse it like that.
That's what I'm running into...the constant never gets passed to the html file (which makes my if statement always false). Wondering if I am missing something where the constant could be passed to the html file.
Appreciate the extensions/mods/support then buy me a beerImage
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
User avatar
Nelsaidi
Registered User
Posts: 525
Joined: Mon Feb 11, 2008 1:59 pm
Location: London, UK
Contact:

Re: Passing constants to an html file

Post by Nelsaidi »

Define it as a template variable in the array.
Image
Click here to find out what eRepublik is.
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52127
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Passing constants to an html file

Post by Brf »

That probably wouldnt work.
He is trying to put a variable on the right-hand side of the comparison. As far as I can tell, only numeric and string constants can be used on the right-hand side.
User avatar
RMcGirr83
Former Team Member
Posts: 21593
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Passing constants to an html file

Post by RMcGirr83 »

Brf wrote:As far as I can tell, only numeric and string constants can be used on the right-hand side.
The constant is defined as a numeric....
RMcGirr83 wrote:

Code: Select all

define('blah_blah_blah',1);
No?
Appreciate the extensions/mods/support then buy me a beerImage
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
User avatar
EXreaction
Former Team Member
Posts: 5666
Joined: Sun Aug 21, 2005 9:31 pm
Location: Wisconsin, U.S.
Name: Nathan

Re: Passing constants to an html file

Post by EXreaction »

You would have to use PHP code inside of the templates.

From what Brf has said, I am not sure if the template system does not allow variables on the right side (though I am not sure why that limitation would be in place if it was), but if you were trying to use a constant, it would just assume you are trying to use a template variable and thus convert it to a template variable in the statement.
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 26842
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: Passing constants to an html file

Post by Paul »

Just asign it normally to the template with assign_vars, and you can use it ;)
Knock knock
Race condition
Who's there?

My BlogMy Photosmy phpBB Extensionscustom phpBB work & Development
User avatar
RMcGirr83
Former Team Member
Posts: 21593
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Passing constants to an html file

Post by RMcGirr83 »

Paul wrote:Just asign it normally to the template with assign_vars, and you can use it ;)
Why I never thought of that, I have no idea. There are multiple constants though, guess I should have stated that from the outset. I suppose

Code: Select all

$some_var = '';
if($some_var == SOME_CONSTANT1)
{
  $some_other_var = SOME_CONSTANT1;
}
elseif($some_var == SOME_CONSTANT2)
{
  $some_other_var = SOME_CONSTANT2;
}
etc...
would work or, can I get away with

Code: Select all

<!-- IF whatever == 1 -->true<!-- ENDIF -->
<!-- IF whatever == 2 -->true<!-- ENDIF -->
which would be "better" from a validation point of view?
Appreciate the extensions/mods/support then buy me a beerImage
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
pixel001
Registered User
Posts: 100
Joined: Thu Aug 23, 2007 11:38 am

Re: Passing constants to an html file

Post by pixel001 »

why not just

Code: Select all

$template->assign_vars(array(  

    'S_SOME_CONSTANT1' => SOME_CONSTANT1
));
and in your html

Code: Select all

<!-- IF S_SOME_CONSTANT1 == 1 -->true<!-- ENDIF -->
User avatar
RMcGirr83
Former Team Member
Posts: 21593
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Passing constants to an html file

Post by RMcGirr83 »

Code: Select all

		<dd>
			<label for="xfire_style1"><input type="radio" name="xfire_style" id="xfire_style1" value="1"<!-- IF XFIRE_STYLE == 1 --> checked="checked"<!-- ENDIF --> style="margin: 2px;" /> {L_XFIRE_SHADOW}</label>
			<label for="xfire_style2"><input type="radio" name="xfire_style" id="xfire_style2" value="2"<!-- IF XFIRE_STYLE == 2 --> checked="checked"<!-- ENDIF --> style="margin: 2px;" /> {L_XFIRE_COMBAT}</label>
			<label for="xfire_style3"><input type="radio" name="xfire_style" id="xfire_style3" value="3"<!-- IF XFIRE_STYLE == 3 --> checked="checked"<!-- ENDIF --> style="margin: 2px;" /> {L_XFIRE_SCIFI}</label>
			<label for="xfire_style4"><input type="radio" name="xfire_style" id="xfire_style4" value="4"<!-- IF XFIRE_STYLE == 4 --> checked="checked"<!-- ENDIF --> style="margin: 2px;" /> {L_XFIRE_FANTASY}</label>
			<label for="xfire_style5"><input type="radio" name="xfire_style" id="xfire_style5" value="5"<!-- IF XFIRE_STYLE == 5 --> checked="checked"<!-- ENDIF --> style="margin: 2px;" /> {L_XFIRE_WOW}</label>
			<label for="xfire_style6"><input type="radio" name="xfire_style" id="xfire_style6" value="6"<!-- IF XFIRE_STYLE == 6 --> checked="checked"<!-- ENDIF --> style="margin: 2px;" /> {L_XFIRE_DEFAULT}</label>
		</dd>
is what I have now that works, but I would like to change the numbers (1,2,3,4,5,6) to constants. I'm not even sure if I need to do that (replace with constants that is).
Appreciate the extensions/mods/support then buy me a beerImage
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
User avatar
Nelsaidi
Registered User
Posts: 525
Joined: Mon Feb 11, 2008 1:59 pm
Location: London, UK
Contact:

Re: Passing constants to an html file

Post by Nelsaidi »

On this note, if i set a variable using '$template->assign_vars(array(

'S_SOME_CONSTANT1' => SOME_CONSTANT1
));'

Then, i do it again but to define more constants, will it work? Will they get over-written or be given errors?
Image
Click here to find out what eRepublik is.
Locked

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