include name from variable name? help?

include name from variable name? help?

am 03.12.2007 00:44:12 von atwiawomo

Hi

This may be simple to solve, but I can't seem to do it :(

I am trying to generate an include name on an image gallery page from
a variable name.
By this I mean I already have a numeric value set the variable
$imageCat.

What I want to do is pull in an external include file using the
variable as the file name. So if $imageCat is set to 2 I want to bring
in 2.html ($imageCat.html).

I can hard code each include request as such:

{if $imageCat=="2"}
{php}
include ("2.php");
{/php}
{/if}

But I am dealing with oodles of categories so this file would be huge.
A dynamic option would be very cool but I just can't seem to get my
syntax right.

If anyone could give me even a vague pointer; I would be sooooo
greatful.

Many thanks

Mr M

Re: include name from variable name? help?

am 03.12.2007 01:04:52 von Hans-Peter Sauer

A loop might a be idea if everything is a number .

$loopy=1;
while ($loopy<20)
{
if ($imagecat==$loopy) {$batman=$loopy . ".php"; include($batman);}
$loopy=$loopy+1;
}

The above code is untested and really just intended to get you started .



<>



> I am trying to generate an include name on an image gallery page from
> a variable name.
> By this I mean I already have a numeric value set the variable
> $imageCat.
>
> What I want to do is pull in an external include file using the
> variable as the file name. So if $imageCat is set to 2 I want to bring
> in 2.html ($imageCat.html).
>
> I can hard code each include request as such:
>
> {if $imageCat=="2"}
> {php}
> include ("2.php");
> {/php}
> {/if}
>
> But I am dealing with oodles of categories so this file would be huge.
> A dynamic option would be very cool but I just can't seem to get my
> syntax right.
>

Re: include name from variable name? help?

am 03.12.2007 01:23:12 von Jerry Stuckle

atwiawomo@yahoo.com wrote:
> Hi
>
> This may be simple to solve, but I can't seem to do it :(
>
> I am trying to generate an include name on an image gallery page from
> a variable name.
> By this I mean I already have a numeric value set the variable
> $imageCat.
>
> What I want to do is pull in an external include file using the
> variable as the file name. So if $imageCat is set to 2 I want to bring
> in 2.html ($imageCat.html).
>
> I can hard code each include request as such:
>
> {if $imageCat=="2"}
> {php}
> include ("2.php");
> {/php}
> {/if}
>
> But I am dealing with oodles of categories so this file would be huge.
> A dynamic option would be very cool but I just can't seem to get my
> syntax right.
>
> If anyone could give me even a vague pointer; I would be sooooo
> greatful.
>
> Many thanks
>
> Mr M
>

I'm not sure what you're using, but {php} is not normal PHP syntax.

In PHP you could do something as easy as

include ($imageCat.'.'php');

But not knowing what you're using, I have no idea if it will work or not
for this.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: include name from variable name? help?

am 03.12.2007 11:19:55 von atwiawomo

Thanks for getting back to me.

It's just a regular php page I'm trying to do this with.

I couldn't get your suggestion below to work.

This works fine but still isn't dynamic:
include (include ("1.php");

It's been quite a while since I did any PHP so am pulling my hair out
about something that should be fairly straight forward.

Mr M


>
> I'm not sure what you're using, but {php} is not normal PHP syntax.
>
> In PHP you could do something as easy as
>
> include ($imageCat.'.'php');
>
> But not knowing what you're using, I have no idea if it will work or not
> for this.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================

Re: include name from variable name? help?

am 03.12.2007 11:31:44 von luiheidsgoeroe

On Mon, 03 Dec 2007 00:44:12 +0100, wrote:
> This may be simple to solve, but I can't seem to do it :(
>
> I am trying to generate an include name on an image gallery page from
> a variable name.
> By this I mean I already have a numeric value set the variable
> $imageCat.
>
> What I want to do is pull in an external include file using the
> variable as the file name. So if $imageCat is set to 2 I want to bring=

> in 2.html ($imageCat.html).
>
> I can hard code each include request as such:
>
> {if $imageCat=="2"}
> {php}
> include ("2.php");
> {/php}
> {/if}

What kind of templating engine is this? Consult their documentation on t=
he =

subject of includes.
-- =

Rik Wasmus

Re: include name from variable name? help?

am 03.12.2007 13:45:51 von Jerry Stuckle

atwiawomo@yahoo.com wrote:
>> I'm not sure what you're using, but {php} is not normal PHP syntax.
>>
>> In PHP you could do something as easy as
>>
>> include ($imageCat.'.'php');
>>
>> But not knowing what you're using, I have no idea if it will work or not
>> for this.
>>
> Thanks for getting back to me.
>
> It's just a regular php page I'm trying to do this with.
>
> I couldn't get your suggestion below to work.
>
> This works fine but still isn't dynamic:
> include (include ("1.php");
>
> It's been quite a while since I did any PHP so am pulling my hair out
> about something that should be fairly straight forward.
>
> Mr M
>
>

(Top posting fixed)

This is not legal PHP code. Obviously you're using some templating
system, but you've never told us what you're using.

You really need to be asking these questions in the support group for
your templating system.

And please don't top post.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: include name from variable name? help?

am 03.12.2007 15:51:35 von Acrobatic

This looks like Smarty templating... if you're using Smarty, then the
code would be something like:

{if $imageCat=="2"}
{php}
$imageCat = $smarty->get_template_vars('imageCat');
include ($imageCat . ".php");
{/php}
{/if}


Make sure you set the Smarty variable of $imageCat with
"$yourSmartyForm->assign('imageCat','2');


On Dec 2, 5:44 pm, atwiaw...@yahoo.com wrote:
> Hi
>
> This may be simple to solve, but I can't seem to do it :(
>
> I am trying to generate an include name on an image gallery page from
> a variable name.
> By this I mean I already have a numeric value set the variable
> $imageCat.
>
> What I want to do is pull in an external include file using the
> variable as the file name. So if $imageCat is set to 2 I want to bring
> in 2.html ($imageCat.html).
>
> I can hard code each include request as such:
>
> {if $imageCat=="2"}
> {php}
> include ("2.php");
> {/php}
> {/if}
>
> But I am dealing with oodles of categories so this file would be huge.
> A dynamic option would be very cool but I just can't seem to get my
> syntax right.
>
> If anyone could give me even a vague pointer; I would be sooooo
> greatful.
>
> Many thanks
>
> Mr M

Re: include name from variable name? help?

am 04.12.2007 01:00:24 von atwiawomo

Hi Acrobatic

Yes, I should have said earlier; it is smarty.

I understand the first bit, but the bit regarding "$yourSmartyForm-
>assign('imageCat','2'); I'm a little lost with.

The code is for PHP Classifieds from DeltaScripts.

I'm getting nowhere on their forum and support system with this :(

Re: include name from variable name? help?

am 04.12.2007 23:26:24 von Acrobatic

> I understand the first bit, but the bit regarding "$yourSmartyForm-
>
> >assign('imageCat','2'); I'm a little lost with.

In your code you need to assign a Smarty variable with the value of
the imageCat you want. Are you using Smarty forms, ie "$yourSmartyForm
= new Smarty();"

If so, then you can assign a variable to be used in the {php} script
by saying $yourSmartyForm->assign('imageCat','2');

Then reference "$imageCat" within the {php} blocks. Clear as mud :)