Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Cant access $myVariable!


Go to End


12 Posts   1819 Views

Avatar
wilsonStaff

Community Member, 143 Posts

10 October 2012 at 7:39am

Edited: 10/10/2012 10:32am

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!

Avatar
copernican

Community Member, 189 Posts

10 October 2012 at 10:49am

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

Avatar
wilsonStaff

Community Member, 143 Posts

10 October 2012 at 10:53am

Edited: 10/10/2012 10:58am

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" />

Avatar
wilsonStaff

Community Member, 143 Posts

10 October 2012 at 12:16pm

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!

Avatar
copernican

Community Member, 189 Posts

11 October 2012 at 1:26am

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.

Avatar
wilsonStaff

Community Member, 143 Posts

11 October 2012 at 1:57am

Edited: 11/10/2012 1:58am

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!

Avatar
copernican

Community Member, 189 Posts

11 October 2012 at 2:00am

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.

Avatar
wilsonStaff

Community Member, 143 Posts

11 October 2012 at 2:06am

Edited: 11/10/2012 2:07am

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!

Go to Top