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

Issues with parts of the 'Working with files and Images' lession


Go to End


5 Posts   1608 Views

Avatar
Twitchnz

Community Member, 3 Posts

11 March 2016 at 5:00pm

I have been running through all the tutorial videos on your site but ran into a few issues where what seems to work in the vid does not work for me. Granted I am new to all this so highly likely to have made a mistake...however here is my issue (for whatever reason I cannot post this as a question against the actual lesson):

For some reason $Photo and $Brochure (these are created as part of the 'has_one' call in ArticlePage.php) are not acceptable calls when put in ArticlePage.ss. So when using the conditional statement to check if there is a brochure(pdf) attached to the article page it never evaluates to true.
Similar for the $Photo on articlepage.ss in that any call to $Photo never finds anything . However $Photo.CroppedImage(242, 156) does work when put in the ArticleHolder.ss
I noticed that using $BrochureID in a conditional statement work in ArticlePage.ss but not $Brochure or $Photo.

Tried using Code repository versions of ArticlePage.ss and ArticlePage.php in case I have made mistakes but still the same.

Any suggestions on what could be going wrong here?

Avatar
Friizu

Community Member, 17 Posts

12 March 2016 at 1:16am

Edited: 12/03/2016 1:19am

Hei

what about

$Photo.Filename 
$Brochure.URL

Are you getting paths if u add those in your ArticlePage.ss template?

What's code in your ArticlePage.php?

Example:

class ArticlePage extends Page {
private static $has_one = array(
    'Photo' => 'Image',
    'Brochure' => 'File'
    );
    public function getCMSFields() {
        $fields = parent::getCMSFields();
		$fields->addFieldToTab("Root.Main", new UploadField('Photo'));
        	$fields->addFieldToTab("Root.Main", new FileField('Brochure'));
        return $fields;
    }
}

Did u made /dev/build/?flush=all after you added changes to your ArticlePage.php file?
Also you should run development site in dev mode, so you can get errors after you make dev/build/?flush=all

Avatar
Twitchnz

Community Member, 3 Posts

14 March 2016 at 3:00pm

Edited: 14/03/2016 3:04pm

Using $Photo.Filename or $Brochure.URL does nothing as calls to $Photo and $Brochure do nothing.
To clarity using $Photo.setWidth(750) in ArticlePage.ss like in the tutorial, fails to inject the image into the html. I.e. when I inspect the source of the actual page there is no <img> tag present unlike on the page that has type ArticleHolder which seems to accept calls like $Photo.CroppedImage(242, 156) and inserts the correct img tag with src etc.

Forgot to mention that I always remember to build and flush so that is not the issue.

Tried putting site in dev mode...no errors

Originally I had in ArticlePage.ss, exactly as shown in the video:

 <div class="blog-main-image">
					$Photo.SetWidth(750)
					<div class="tag"><i class="fa fa-file-text"></i></div>
				</div>

Then tried copying the ArticlePage.ss from the tutorial so have:

<div class="blog-main-image">
				<% with $Photo.SetWidth(750) %>
					<img src="$URL" width="$Width" height="$Height" class="my-custom-class">
				<% end_with %>
					<div class="tag"><i class="fa fa-file-text"></i></div>
				</div>

Using the tutorial code repository version injects the <img> tags but like this
<img src="" width="" height="" class="my-custom-class">

So clearly the $Photo calls are not working at this page level

Avatar
Friizu

Community Member, 17 Posts

14 March 2016 at 9:11pm

Hei,

I think problem is somewhere else not in template. What's code in your ArticlePage.php, ArticleHolder.php and Page.php?

Also maybe there is some kind of conflict?
You can try to change $Photo to $Photo2 for example, both in ss and php files (in case some plugin etc already have $Photo in use).

Avatar
Twitchnz

Community Member, 3 Posts

15 March 2016 at 10:35am

Thank you for your assistance and you were very much correct. The problem was I had inadvertently changed the name of the ArticlePage_Controller in ArticlePage.php so the controller was not picking up anything.

All sorted now. Cheers