Jump to:

23001 Posts in 11854 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » question add image template - noob

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 3
Go to End
Author Topic: 1920 Views
  • wachupe
    Avatar
    Community Member
    15 Posts

    Re: question add image template - noob Link to this post

    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

  • zenmonkey
    Avatar
    Community Member
    524 Posts

    Re: question add image template - noob Link to this post

    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

  • wachupe
    Avatar
    Community Member
    15 Posts

    Re: question add image template - noob Link to this post

    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

  • zenmonkey
    Avatar
    Community Member
    524 Posts

    Re: question add image template - noob Link to this post

    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

  • wachupe
    Avatar
    Community Member
    15 Posts

    Re: question add image template - noob Link to this post

    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

  • zenmonkey
    Avatar
    Community Member
    524 Posts

    Re: question add image template - noob Link to this post

    Do you mean call it in the template?

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

  • wachupe
    Avatar
    Community Member
    15 Posts

    Re: question add image template - noob Link to this post

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

    +999 for you c:

  • zenmonkey
    Avatar
    Community Member
    524 Posts

    Re: question add image template - noob Link to this post

    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

    1920 Views
Page: 1 2 3
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.