Results 1 to 10 of 10

Thread: Variables inside a file inserted with {{file::php-file}}

  1. #1
    New user
    Join Date
    08-14-09.
    Posts
    28

    Default Variables inside a file inserted with {{file::php-file}}

    Hello,

    Can somebody tell me how to use insert-tags (like {{user::lastname}}) from inside a .php-file used in a custom-html module through {{file::.php-file}}? It would be easy if you could nest them, like {{file::.php-file?lastname={{user::lastname}}}}, but this doesn't work. What is the proper method to access this information?

    Thanks a lot!

  2. #2
    User Toflar's Avatar
    Join Date
    06-19-09.
    Location
    Lyss, Switzerland
    Posts
    170

    Default Re: Variables inside a file inserted with {{file::php-file}}

    Hmm, try like this:

    Code:
    {{file::.php-file?lastname=<?php echo $this->replaceInsertTags('{{user::lastname}}'); ?>}}
    and don't forget to write the {{}} on your own as some OS seem to put hidden chars between the brackets when copying
    Regards

    Yanick - Contao core developer @terminal42 gmbh

  3. #3
    New user
    Join Date
    08-14-09.
    Posts
    28

    Default Re: Variables inside a file inserted with {{file::php-file}}

    Thank you Toflar, your tip solved my problem. You cannot however, use php-tags inside Custom-HTML modules. But this doesn't really matter.

  4. #4
    User
    Join Date
    04-27-10.
    Posts
    134

    Default Re: Variables inside a file inserted with {{file::php-file}}

    Hi,
    Does anyone know if it's possible to have a tag within a tag?

    I'm pulling a random image from an OSCommerce database using a custom script but would like to be able to crop this using the image {{image::*} tag.
    Was hoping to be able to do something like {{image::{{file::randomimage.php}}?width=200&mode= crop}}
    With the randomimage.php outputting a basic url.

    Cheers

  5. #5
    Experienced user
    Join Date
    06-10-09.
    Location
    Atlanta, Georgia
    Posts
    611

    Default Re: Variables inside a file inserted with {{file::php-file}}

    @alewar - I believe you just need to go into Settings and add an "Allowed HTML tag" of <?php>

    @vinchenzison - My hunch is that this will not work. I did a quick test with a replacement tag within another and it doesn't parse properly. Are you getting any kind of output?

  6. #6
    User
    Join Date
    04-27-10.
    Posts
    134

    Default Re: Variables inside a file inserted with {{file::php-file}}

    The only output that gets printed on screen is "?width=200&mode=crop}}"
    The {{image::{{file::featuredproduct.php}} renders as [img][/img] in html

    I also tried adding an insert tag into the php file to see if it was read by contao but it doesn't

  7. #7
    Experienced user
    Join Date
    06-10-09.
    Location
    Atlanta, Georgia
    Posts
    611

    Default Re: Variables inside a file inserted with {{file::php-file}}

    I think the best solution is to have all the output generated in the php file. You could always borrow the code that crops the photos. Or, just do something like this to faux-crop the images in css:

    Code:
    <div class="randoms">
    [img]somewhere/image.jpg[/img]
    </div>
    
    img.thePhoto {
    width: 200px;
    }
    div.randoms {
    width: 200px;
    height: 200px;
    overflow: none;
    }
    This is all theoretical, untested and from the top of my head.

  8. #8
    User
    Join Date
    04-27-10.
    Posts
    134

    Default Re: Variables inside a file inserted with {{file::php-file}}

    Thanks for that.
    My mistake though, when I said crop, I actually meant resize to 200px width.

  9. #9
    Experienced user
    Join Date
    06-10-09.
    Location
    Atlanta, Georgia
    Posts
    611

    Default Re: Variables inside a file inserted with {{file::php-file}}

    Since you don't need to crop, I'd just re-size the photo with css. In my opinion, this is perfectly acceptable. It's even more acceptable if you are taking a small photo (around 400 or 600px) and changing it to 200px. The browser renders css resizes best when they are a multiple of the original. So, it is best to take a 600px photo and display it at 200px, instead of 180px.

    Hopefully this makes sense.

  10. #10
    User Toflar's Avatar
    Join Date
    06-19-09.
    Location
    Lyss, Switzerland
    Posts
    170

    Default Re: Variables inside a file inserted with {{file::php-file}}

    Or use the following code within your template:
    Code:
    [img]<?php echo $this->getImage('path/to/original.jpg', $width, $height, $mode); ?>[/img]
    Both $width or $height are optional but there has to be at least one of them
    E.g. you want to resize your image to a height of 150px and keep the proportions:
    Code:
    $this->getImage('mypic.jpg', null, 150);
    Regards

    Yanick - Contao core developer @terminal42 gmbh

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •