Jump to:

23552 Posts in 19349 Topics by 2891 members

General Questions

SilverStripe Forums » General Questions » Generator HTML Tag

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
Go to End
Author Topic: 8600 Views
  • inCharge
    Avatar
    Community Member
    102 Posts

    Re: Generator HTML Tag Link to this post

    Hi Bastir

    There are a couple of things going wrong here...

    Restore the original SiteTree.php. Changing core code makes it hard to upgrade. (Willr said
    Copy the MetaTags() function from SiteTree.php to your own Page.php)

    Ed's GetCanonical and my CanonicalURL are two different techniques. you don't need both. I think the CanonicalURL method is simpler, so is recommended if you're just getting started with SS.

    After changing the .ss file, you need to browse to the page adding ?flush=1 to the URL to clear the cache.

    Thanks,
    Jules (inCharge Ltd)

  • Bastir
    Avatar
    Community Member
    8 Posts

    Re: Generator HTML Tag Link to this post

    Hi Jules,

    Thanks for the advice!

    I added the code from your post to the end of the page.php an into the page.ss below the Basetag.

    after that i reloaded everything by ?flush=1 and i also tried dev/build

    but i only get a empty result <link rel="canonical" href="" />

    is their any additional configuration necssary?

    URL: www.inzenaro.de

    thy in advance

    Best Regards bastiR

  • inCharge
    Avatar
    Community Member
    102 Posts

    Re: Generator HTML Tag Link to this post

    You can easily find out which bit is not working with a bit of investigation.

    When you put a $Tag in the .ss, then it calls the function in the Page class and replaces $Tag with the value returned by the function.

    So if you have this in Page.php...

    function CanonicalURL() {
       return "hello";
    }

    ...and this in Page.ss

    <div>$CanonicalURL</div>

    then the result in teh browser should be

       hello

    Does that work for you?

  • Bastir
    Avatar
    Community Member
    8 Posts

    Re: Generator HTML Tag Link to this post

    Hi Jules,

    No i only get a empty <div></div> so i Think the problem is in the Page.php

    ------------------------------
    <?php
    class Page extends SiteTree {

       public static $db = array(
       );

       public static $has_one = array(
       );

    }

    function CanonicalURL() {
    return "hello";
    }

    class Page_Controller extends ContentController {

       /**
        * An array of actions that can be accessed via a request. Each array element should be an action name, and the
        * permissions or conditions required to allow the user to access it.
        *
        * <code>
        * array (
        * 'action', // anyone can access this action
        * 'action' => true, // same as above
        * 'action' => 'ADMIN', // you must have ADMIN permissions to access this action
        * 'action' => '->checkAction' // you can only access this action if $this->checkAction() returns true
        * );
        * </code>
        *
        * @var array
        */
       public static $allowed_actions = array (
       );

       public function init() {
          parent::init();

          // Note: you should use SS template require tags inside your templates
          // instead of putting Requirements calls here. However these are
          // included so that our older themes still work
          Requirements::themedCSS('layout');
          Requirements::themedCSS('typography');
          Requirements::themedCSS('form');
          Requirements::themedCSS('flexslider');
    Requirements::css(SSPE_DIR."/css/960gs/960.css");
       }
    }

    ----------------------------------

    any idea?

    Best regards bastiR

  • inCharge
    Avatar
    Community Member
    102 Posts

    Re: Generator HTML Tag Link to this post

    The good news is that I can't see anything wrong with your code. The bad new is...I can't see anything wrong with your code.

    Maybe the Page.php you're editing isn't the one that SilverSitripe is using. What folder is it in? Is it really called Page.php?

    Are flexslider.cc and 960.css being included in the header?

    What happens if you add the following code inside the init() function?

    throw new Exception("Hello!");

  • Bastir
    Avatar
    Community Member
    8 Posts

    Re: Generator HTML Tag Link to this post

    Hi,

    path: mysite/code/page.php

    Flexslider and 960.css are included in the header.

    i insert the code snippet to the page.php like:

       public function init() {
          parent::init();

          // Note: you should use SS template require tags inside your templates
          // instead of putting Requirements calls here. However these are
          // included so that our older themes still work
          Requirements::themedCSS('layout');
          Requirements::themedCSS('typography');
          Requirements::themedCSS('form');
          Requirements::themedCSS('flexslider');
    Requirements::css(SSPE_DIR."/css/960gs/960.css");
          throw new Exception("Hello!");
       }
    }

    on the frontend i get an Error 500 on ervery page.

    in the html source code the canonicla and div is away.

    i'm totaly helpless what is the failure.

    Thans for your help in advance:)

  • inCharge
    Avatar
    Community Member
    102 Posts

    Re: Generator HTML Tag Link to this post

    Ah, I see it. CanonicalURL is outside the Page class. You need to move it inside.

    Change...

    }

    function CanonicalURL() {
    return "hello";
    }

    ...to...

       function CanonicalURL() {
          return "hello";
       }

    } /* end of the Page class */

    > i'm totaly helpless what is the failure.

    No you're not! Don't just scratch your head saying 'it SHOULD work'. Try different tests to close in on the problem.

  • Bastir
    Avatar
    Community Member
    8 Posts

    Re: Generator HTML Tag Link to this post

    Thanks a lot, not it works and i'm happy again;)

    Have a nice weekend

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