Jump to:

23459 Posts in 18906 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Cant access $myVariable!

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 751 Views
  • wilsonStaff
    Avatar
    Community Member
    142 Posts

    Cant access $myVariable! Link to this post

    H, still trying to solve this.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    In my page class, I have a function that take all images from a selected folder, and returns list of images.
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    return ($folder = $this->PortfolioFolder()) ? DataObject::get("Image", "ParentID = '{$folder->ID}'") : false;

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    In my template, i have this
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

       <% control ImagesIDE %>
          <img src="$URL" alt="$Caption" />
       <% end_control %>

    which i wrapped within Fotorama div. Works fine. Note the red bit.

    Problem is that i need to acces a caption for that image and my function isnt returning other thing that the $URL variable.

    Fotorama uses the alt="..." for description.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Solution i thought of....
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    While looking for solutions, i tryied

    <img src="$URL" alt="$Title" />

    and it returned this

    <img src="...." alt="image_aaa.jpg" />

    So i said, where does that comes from? Quickly, i thought about the FILES pabel into the CMS. Yes, there is a title there.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    QUESTION
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    Is there a way i could add another textfield into that part of the CMS? Like that:

    So i could use

    <img src="$URL" alt="$Caption" />

    Thanks!

  • IOTI
    Avatar
    Community Member
    189 Posts

    Re: Cant access $myVariable! Link to this post

    Why don't you just use the title field as your alt tag? Is there a specific reason you can't?

  • wilsonStaff
    Avatar
    Community Member
    142 Posts

    Re: Cant access $myVariable! Link to this post

    Well, as i said:

    <img src="$URL" alt="$Title" />

    returns this

    <img src="...." alt="image_aaa.jpg" />

    The NAME of the file

    = = =

    And when i try to change de Title parameter in the FILES panel (as shown below into the CMS), the CMS freezes...

    = = =

    Is is a bug? I mean could it be that simple as changing the title of my image and then <img src="..." alt="$Title" />

  • wilsonStaff
    Avatar
    Community Member
    142 Posts

    Re: Cant access $myVariable! Link to this post

    Well, well, it seems that i CAN now edit images and attribute a description into title and access it via alt="$Title"

    while i couldnt do it previously.

    One worthy note is that if i use

    UPLOAD IMAGES BUTTON => it fails to edit

    DRAG & DROP => i can edit details....

    - - -

    Anyhow, its not that relevent to my problem as i need to be able to add style to that description, like wrapping a word or two between <strong> tags.

    - - -

    So, can one add customs textfields into the CMS IMG ADMIN panel?

    Thanks!

  • IOTI
    Avatar
    Community Member
    189 Posts

    Re: Cant access $myVariable! Link to this post

    It appears you can.. i didn't test as an extension but it should work.

    You want to first extend the File class through a DataExtension, and add your new description text field

    class FileExtension extends DataExtension {
    public static $db=array(
    'Description'=>'Text'
    );
    }

    then you want to add your new field through the updateCMSFields() function like so in your FileExtension class

    public function updateCMSFields(FieldList $fields){
    $fields->addFieldToTab('Root.Main', new TextField('Description'));
    }

    and then in your _config.php add

    Object::add_extension('File', 'FileExtension');

    and then do a dev/build/?flush=all. Let me know if that works or not.

  • wilsonStaff
    Avatar
    Community Member
    142 Posts

    Re: Cant access $myVariable! Link to this post

    Hi, first thanks for helping. It is not working though. the CMS freezes. Let me recap.

    /******** mysite/code/FileExtension.php

    class FileExtension extends DataExtension {
    public static $db=array(
    'Description'=>'Text'
    );

    public function updateCMSFields(FieldList $fields){
    $fields->addFieldToTab('Root.Main', new TextField('Description'));
    }
    }

    /********* mysite/_config.php

    Object::add_extension('File', 'FileExtension');

    After a dev/build, the CMS shows nothing. I can log but if i click on FILES, the right part of the CMS goes blank.

    I am using SS3, if that changes something.

    Thanks!

  • IOTI
    Avatar
    Community Member
    189 Posts

    Re: Cant access $myVariable! Link to this post

    Did you also do a ?flush=all ?

    Check your console for any errors and let me know what it says. If you can't get that I should be able to try this myself again later today.

  • wilsonStaff
    Avatar
    Community Member
    142 Posts

    Re: Cant access $myVariable! Link to this post

    Hi, no error that i know of. Chrome Error Console shows nothing.

    Can you confirm that i have to:

    1 - copy your code into FileExtension.php WITH NO TYPO.....

    class FileExtension extends DataExtension {
    public static $db=array(
    'Description'=>'Text'
    );

    public function updateCMSFields(FieldList $fields){
    $fields->addFieldToTab('Root.Main', new TextField('Description'));
    }
    }

    Question, no controller needed????

    2 - place FileExtension.php into mysite/code

    3 - copy your code (below into mysite/_config.php

    Object::add_extension('File', 'FileExtension');

    4 - Run a dev/build?flush=all

    Thanks!

    751 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.