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.

General Questions

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

Cant access $myVariable!


Go to End
Reply

12 Posts   788 Views

Avatar
wilsonStaff

10 October 2012 at 7:39am (Last edited: 10 October 2012 10:32am), Community Member, 142 Posts

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
IOTI

10 October 2012 at 10:49am Community Member, 189 Posts

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

Avatar
wilsonStaff

10 October 2012 at 10:53am (Last edited: 10 October 2012 10:58am), Community Member, 142 Posts

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

10 October 2012 at 12:16pm Community Member, 142 Posts

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
IOTI

11 October 2012 at 1:26am Community Member, 189 Posts

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

11 October 2012 at 1:57am (Last edited: 11 October 2012 1:58am), Community Member, 142 Posts

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
IOTI

11 October 2012 at 2:00am Community Member, 189 Posts

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

11 October 2012 at 2:06am (Last edited: 11 October 2012 2:07am), Community Member, 142 Posts

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