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

question add image template - noob


Go to End


20 Posts   3780 Views

Avatar
wachupe

Community Member, 15 Posts

15 July 2011 at 8:53am

but example

click on the image and take me to another site...
with the URL to be added to the image when the photo was added to the server through the tab

Avatar
zenmonkey

Community Member, 545 Posts

15 July 2011 at 9:03am

Ah the method I gave you was a way to post an entire folder of images to a page.

If you want an image with a link you'll need to do it totally differently. You'll need to create a DataObject with has Link and an Image. Take a look here

http://silverstripe.org/template-questions/show/17434

Avatar
wachupe

Community Member, 15 Posts

16 July 2011 at 2:18am

this is my code for upload images

<?php
class Logo extends DataObject {
 
   static $db = array(
	  'TextoAlternativo' => 'Varchar',
	  'Link'=>'Varchar'
   );

   static $has_one = array(
	   
       'LogoImage' => 'Image'
   );


   function getCMSFields_forPopup() {
     return new FieldSet(
	new TextField('TextoAlternativo',"Texto Alternativo (para google)"),
	new TextField('Link',"Link externo"),
	new ImageField('LogoImage', 'Agregar imagen del logo',null,null,null,'assets/Logos')
	);
   
   } 
}
?>

and with the other function calls this images to show in template

Avatar
zenmonkey

Community Member, 545 Posts

16 July 2011 at 2:31am

Okay then you'll to create a $has_many relation on whatever page type will hold the Logo object and add an ImageDataObjectManager to the CMS fields

Avatar
wachupe

Community Member, 15 Posts

16 July 2011 at 4:18am

Edited: 16/07/2011 6:17am

i have this in

<?php

class Inicio extends Page{

	static $icon = "localhost/images/treeicons/homepage";   
	
	static $has_many = array(
     'Logos'=>'Logo'
	);
	

	function getCMSFields() {		
		
		$fields = parent::getCMSFields();     
		$Logox = new FileDataObjectManager(
		$this,
		'Logos',
		'Logo',
		'LogoImage',
		array(
			'TextoAlternativo' =>'Texto Alternativo (para google)',
			'Link' =>'Link Externo'			
		),
		'getCMSFields_forPopup'
		);		
		$Logox->setAddTitle( 'A Logo' );
		$fields->addFieldToTab( 'Root.Content.Logos', $Logox );
     	
		
		
		return $fields;
	}
}

class Inicio_Controller extends Page_Controller {

	
}	

when I upload the images through the tab in the database is created a field called "logo" which contains these images
how do I call all the field with the images?
because in this field not have a folder that store these images

Avatar
zenmonkey

Community Member, 545 Posts

19 July 2011 at 1:13am

Do you mean call it in the template?

<% control Logos %>
<a href="$Link">$LogoImage</a>
<% end_control %>

Avatar
wachupe

Community Member, 15 Posts

19 July 2011 at 1:33am

thx zenmonkey works perfect
and sorry for the problems :c
you are the best lml

+999 for you c:

Avatar
zenmonkey

Community Member, 545 Posts

19 July 2011 at 1:47am

No Problem. It takes a little while to wrap your head around it. When I started with SS I didn't even know any PHP.

Just need to remember that when you call the relation in the template you need to use plural name and that teh Name of the function to call the image will be whatever you called the $Image relation on the dataobject (in this case LogoImage). You can also change the FileDataObjectManager to an ImageDataObjectManger. It just gives you some more viewing options in the CMS

Cheers