Jump to:

517 Posts in 247 Topics by 260 members

Content Editor Discussions

SilverStripe Forums » Content Editor Discussions » Making content on all pages editing on CMS

Forum for content editors and CMS users.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2 3
Go to End
Author Topic: 4638 Views
  • steve_nyhof
    Avatar
    Community Member
    224 Posts

    Re: Making content on all pages editing on CMS Link to this post

    Hey SilverRay!

    I got it to work. I just did exactly what your example showed and I got that to work.

    Now I will see what I can do to adapt it... I'll keep you informed.

    Thank you,
    Steve

  • steve_nyhof
    Avatar
    Community Member
    224 Posts

    Re: Making content on all pages editing on CMS Link to this post

    It's all working!

    I have a page called PageGlobal.php - setup the way you mentioned.

    I put this page under an Unpublished page so it does not show up in my navigation.

    I then called the page, Global Settings on Level 2 nav. Published. This is so the page is available. However, because it is under an unpublished page, it does not show up in the site map - that is good.

    However, I also needed to set the google setting to "Not Published" so it is not part of the sitemap.xml file.

    Now my Home page behaves just like any other page, and I have a specific nav page for global settings. This will make more sense to my clients. Plus, before they get the site, all of their pages are already setup, they just need to edit and take it from there.

    Thank you again for offering your help here.
    Steve Nyhof

  • steve_nyhof
    Avatar
    Community Member
    224 Posts

    Re: Making content on all pages editing on CMS Link to this post

    I am trying to add a global background image. I think I am close on this following the advise in this thread...
    I have the code all working on the page. I also have a background image that can be changed per page.

    I get this error when on the "Global" Background Image tab

    [Notice] Undefined index:
    POST /images/index/PageGlobal/25/SiteBackground/EditImageForm

    Line 157 in /home/landingp/public_html/sapphire/core/ClassInfo.php
    Source

    148    /**
    149     * @todo Improve documentation
    150     */
    151    static function ancestry($class, $onlyWithTables = false) {
    152       global $_ALL_CLASSES;
    153
    154       if(is_object($class)) $class = $class->class;
    155       else if(!is_string($class)) user_error("Bad class value " . var_export($class, true) . " passed to ClassInfo::ancestry()", E_USER_WARNING);
    156
    157       $items = $_ALL_CLASSES['parents'][$class];
    158       $items[$class] = $class;
    159       if($onlyWithTables) foreach($items as $item) {
    160          if(!DataObject::has_own_table($item)) unset($items[$item]);
    161       }
    162       return $items;
    163    }

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

    This is working on my Page.ss file

    <% if BackgroundImage %>
    <style>
    body {
       background-image:url($BackgroundImage.URL);
       background-position:top center;
       background-attachment:fixed;
    }
    </style>
    <% else %>
    <% if callGlobalBg.PageGlobal %>
    <style>
    body {
       background-image:url($callGlobalBg.PageGlobal.URL);
       background-position:top center;
       background-attachment:fixed;
    }
    </style>
    <% else %>
    <style>
    body {
       background-image:url(assets/Backgrounds/bg-body.jpg);
       background-position:top center;
       background-attachment:fixed;
    }
    </style>
    <% end_if %>
    <% end_if %>

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

    This is my PageGlobal.php page - everything we have been talking about is working. I am now trying to get the background image to work. I get the error above when trying to add the image on the form.

    <?php

    class PageGlobal extends Page {

    public static $db = array(
    'MyFooter' => 'HTMLText'
    );

    public static $has_one = array(
    "GlobalBackgroundImage" => "Image"
    );

    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab('Root', new TabSet('GlobalContent'));
       
    $fields->addFieldToTab( 'Root.GlobalContent.PageFooter', new HtmlEditorField('MyFooter', 'Edit the content and links below for your business. Make sure to test all the links on your site.'));
    $fields->addFieldToTab( 'Root.GlobalContent.BackgroundImage', new ImageField('SiteBackground', 'Add a site background here. This will change the background image on all pages. This will not override single page backgrounds.'));
       
        $fields->removeByName("ScriptsAndTracking");
        $fields->removeByName("OptionalPageImages");
        $fields->removeByName("StickyNote");
       
    return $fields;
    }

    }

    class PageGlobal_Controller extends Page_Controller {
    }

    ?>

    My Page.php file

    public function callGlobal(){
    return DataObject::get_one('PageGlobal');
    }
       
       public function callGlobalBg(){
    return DataObject::get_one('PageGlobal');
    }

  • steve_nyhof
    Avatar
    Community Member
    224 Posts

    Re: Making content on all pages editing on CMS Link to this post

    I got it all working!

    Here is my code in case someone wants to do the samething with it...

    Page.php

    <?php

    class Page extends SiteTree {
    public static $db = array(
    'HeadTag' => 'HTMLText',
    'TopBodyTag' => 'HTMLText',
    'BotBodyTag' => 'HTMLText',

    'SplitPage' => 'HTMLText',
    'TrackingName' => 'HTMLText',
    'AwebList' => 'HTMLText',
    'ConvPageUrl' => 'HTMLText',
    'CusCompUrl' => 'HTMLText',
    'CusMemID' => 'HTMLText',

    'PopupPosition' => 'HTMLText',
    'PopupNote' => 'HTMLText',
    'PopupHide' => 'HTMLText',
    'PopupShow' => 'Boolean'

    );

    public static $has_one = array(
    "HeaderImage" => "Image",
        "BackgroundImage" => "Image",
        "PopupImage" => "Image"
    );

    function getCMSFields() {
    $fields = parent::getCMSFields();
    //$fields->removeFieldFromTab("Root.Content.Main","MetaTitle");
    //$fields->addFieldToTab("Root.Content.Main", new TextField("MetaTitle", "Title"), "Content");

    //$fields->addFieldToTab('Root', new TabSet('GlobalContent'));
    //$fields->addFieldToTab( 'Root.GlobalContent.FooterContent', new HtmlEditorField('SomeFooter', 'Make sure you are on the Home Page before editing global values. Use the editer below to update your footer content.'));
    //$fields->addFieldToTab( 'Root.GlobalContent.BackgroundImage', new ImageField('GlobalBackgroundImage', 'Make sure you are on the Home Page before editing global values. You can change the background here for the complete site.'));

    $fields->addFieldToTab("Root.Content.ScriptsAndTracking", new TextareaField("HeadTag", "Header Tag Script: (Optional) Add scripts here that need to reside inside the head tags to initiate special or advanced optional website features."));
    $fields->addFieldToTab("Root.Content.ScriptsAndTracking", new TextareaField("TopBodyTag", "After Opening Body Tag Script: (Optional) Add scripts here that need to be initiated at the top of the body content."));
    $fields->addFieldToTab("Root.Content.ScriptsAndTracking", new TextareaField("BotBodyTag", "Before Closing Body Tag Script: (Optional) Add scripts here that need to come after the body content and just above the closing body tag."));

    $fields->addFieldToTab("Root.Content.ScriptsAndTracking", new TextField('TrackingName','Tracking Name: (Optional - Recommended) Give this page a unique name so that when a lead signs up on this page, you will know what page they came through. Example: Use your unique adgroup name, like Internet Marketing Business, or IMB for short.'));
    $fields->addFieldToTab("Root.Content.ScriptsAndTracking", new TextField('SplitPage','Split Page ID: (Optional) Change this to an A or B to identify this page for split testing. Recommended when split testing.'));
    $fields->addFieldToTab("Root.Content.ScriptsAndTracking", new TextField('AwebList','Aweber List Name: (Required with a page that has a sign-up form). Enter the name of the Aweber list name associated with this pages signup form. This will place the lead into your Aweber list.'));
    $fields->addFieldToTab("Root.Content.ScriptsAndTracking", new TextField('ConvPageUrl','Conversion Page URL: (Thank you page). (Required with a page that has a sign-up form). Enter the URL of the conversion page. Example: http://yourdomain.com/conversion-page/?stage= - Make sure to include the http:// - Make sure to include the /?stage= code to protect the page from unauthorized access.'));
    $fields->addFieldToTab("Root.Content.ScriptsAndTracking", new TextField('CusCompUrl','Company Linking Url: (Required with a page that has a sign-up form). Url / Domain Name (Example: MyDomainName.com) associated with your company account - Do NOT include the http:// - This is used in your follow-up email campaign.'));
    $fields->addFieldToTab("Root.Content.ScriptsAndTracking", new TextField('CusMemID','Custom Member ID: (Required with a page that has a sign-up form) The ID associated with your company account, found in the company administration area.'));

    $fields->addFieldToTab("Root.Content.OptionalPageImages", new ImageField("HeaderImage", "Header Image: Your landing page comes with a default header. You can add a unique header here from the Headers folder for this page only."));
    $fields->addFieldToTab("Root.Content.OptionalPageImages", new ImageField("BackgroundImage", "Background Image: Your landing page comes with a default background image. You can add a unique background here from the Background folder for this page only. Images must be a minimum of 1800 x 1200 pixels"));

    $fields->addFieldToTab("Root.Content.StickyNote", new CheckboxField('PopupShow','Show Popup: Check the checkbox if you want to use a sticky note on this page.'));
    $fields->addFieldToTab("Root.Content.StickyNote", new HtmlEditorField('PopupNote','Popup Message: You can write a note, add a link, and even add an image. Make sure to check your work by viewing the page.'));
    $fields->addFieldToTab("Root.Content.StickyNote", new TextField('PopupPosition','Popup Position: Enter 1 for Left side or 2 for Right side'));
    $fields->addFieldToTab("Root.Content.StickyNote", new TextField('PopupHide','Hide After How Many Milliseconds: Enter 10000 to display popup for 10 seconds. Enter 0 to keep it on.'));
    $fields->addFieldToTab("Root.Content.StickyNote", new ImageField("PopupImage", "Popup Background Image: You can select a different popup background image for this sticky note. Select a Stick Note Image from the StickyNotes folder. Click on the (+) next to the folder to show the list of images available."));

    HtmlEditorConfig::get('cms')->insertButtonsAfter('formatselect', 'fontselect', 'fontsizeselect', 'forecolor', 'removeformat');

    HtmlEditorConfig::get('cms')->setOption('verify_html', 'false');

    return $fields;
    }

    }

    class Page_Controller extends ContentController {

       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");
          
       }
       
       
       
       /**
        * Allow Scripts
        */
       
       /*public function getCMSFields() {
          $fields = parent::getCMSFields();
          
          HtmlEditorConfig::get('cms')->setOption('verify_html', 'false');

          return $fields;
          
       }*/
       
       public function BaseTag() {
    return '<base href="'. Director::absoluteBaseURL() . '" />';
    }

       /**
        * Site search form
        */
       function SearchForm() {
          $searchText = isset($_REQUEST['Search']) ? $_REQUEST['Search'] : 'Search';
          $fields = new FieldSet(
           new TextField("Search", "", $searchText)
           );
          $actions = new FieldSet(
           new FormAction('results', 'Search')
           );

           return new SearchForm($this, "SearchForm", $fields, $actions);
       }
       
       /**
        * Process and render search results
        */
       function results($data, $form){
           $data = array(
           'Results' => $form->getResults(),
           'Query' => $form->getSearchQuery(),
           'Title' => 'Search Results'
           );

           return $this->customise($data)->renderWith(array('Page_results', 'Page'));
       }

       public function callGlobalFooter(){
    return DataObject::get_one('PageGlobal');
    }
       
       public function callGlobalBgImage(){
    return DataObject::get_one('PageGlobal');
    }
       
       public function callGlobalHeadScripts(){
    return DataObject::get_one('PageGlobal');
    }
       
       public function callGlobalBodyScripts(){
    return DataObject::get_one('PageGlobal');
    }
       
    }

    ?>

    GlobalPage.php - This is a published page, but under an unpublished page and the google index set to "Not Indexed"

    <?php

    class PageGlobal extends Page {

    public static $db = array(
    'MyFooter' => 'HTMLText',
        'HeadScripts' => 'HTMLText',
        'BodyScripts' => 'HTMLText'
    );

    public static $has_one = array(
    "GlobalBgImage" => "Image"
    );

    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab('Root', new TabSet('GlobalContent'));
       
    $fields->addFieldToTab( 'Root.GlobalContent.PageFooter', new HtmlEditorField('MyFooter', 'Edit the content and links below for your business. Make sure to test all the links on your site.'));
       
    $fields->addFieldToTab( 'Root.GlobalContent.BackgroundImage', new ImageField('GlobalBgImage', 'Add a site background here. This will change the background image on all pages. This will not override single page backgrounds.'));
       
        $fields->addFieldToTab( 'Root.GlobalContent.HeadScripts', new TextareaField('HeadScripts', 'Enter scripts in the head of your site that you want to include on every page.'));
       
        $fields->addFieldToTab( 'Root.GlobalContent.BodyScripts', new TextareaField('BodyScripts', 'Enter scripts in the body of your site that you want to include on every page.'));
       
        $fields->removeByName("ScriptsAndTracking");
        $fields->removeByName("OptionalPageImages");
        $fields->removeByName("StickyNote");
       
    return $fields;
    }

    }

    class PageGlobal_Controller extends Page_Controller {
    }

    ?>

    Some of my Page.ss file - the head

    <head>$MetaTags
    <% base_tag %>
    $HeadTag
    $callGlobalHeadScripts.HeadScripts
    <% if PopupShow %>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type="text/javascript" src="javascript/stayontop.js"></script>
    <script type="text/javascript">alwaysOnTop.init({targetid: "notediv",
       orientation: $PopupPosition, // 1= top/left | 2=top/right | 3= bottom/left | 4= bottom/right
       position: [20, 60], // left and top position
       hideafter: $PopupHide // Hide note after so many milliseconds
       //frequency: 1,//change "1" to "session" for once per browser session
    })</script>
    <% end_if %>

    <link rel="stylesheet" type="text/css" href="themes/site/css/layout.css">

    <% if BackgroundImage %>
    <style>
    body {
       background-image:url($BackgroundImage.URL);
       background-position:top center;
       background-attachment:fixed;
    }
    </style>
    <% else %>
    <% if callGlobalBgImage.GlobalBgImage %>
    <style>
    body {
       background-image:url($callGlobalBgImage.GlobalBgImage.URL);
       background-position:top center;
       background-attachment:fixed;
    }
    </style>
    <% else %>
    <style>
    body {
       background-image:url(assets/Backgrounds/bg-body.jpg);
       background-position:top center;
       background-attachment:fixed;
    }
    </style>
    <% end_if %>
    <% end_if %>

    </head><body>
    $TopBodyTag

    Fields being called in the body...

    $TopBodyTag

    spn = "$SplitPage";
    aweblist = "$AwebList";
    convpageurl = "$ConvPageUrl";
    cuscompurl = "$CusCompUrl";
    cusmemid = "$CusMemID";

    t = "$TrackingName";

    $callGlobalBodyScripts.BodyScripts

    <% if HeaderImage %>
    <div style="padding:0 0 0 0px; margin-bottom:-4px;"> $HeaderImage </div>
    <% else %>
    <div style="padding:0 0 0 0px; margin-bottom:-4px;"> <img src="assets/Headers/defaulttop.png" width="800"/> </div>
    <% end_if %>

    <div class="typography"> $callGlobalFooter.MyFooter </div>

    $BotBodyTag

    Again thank you for all your help with this.
    Steve

    4638 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.