Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Best way to edit page content

alan0209alan0209 New
edited September 2014 in Vanilla 2.0 - 2.8

The home page for my forums is set to "categories" which shows a title of "All Categories" and then a list of the available categories.

  1. Heading: All Categories
  2. Category List

I would like to change the page title to be "Forums" and then insert a paragraph of text welcoming users and providing some simple instructions. Only after this would I like a heading of "Categories" to appear and the list of categories themselves.

  1. Heading: Forums
  2. Welcome
  3. Heading: Categories
  4. Category List

After trawling the forums I found that I could copy a file called all.php from the vanilla/views/categories folder into my theme/views/categories folder and edit that to get the desired effect. The downside of this seems to be that whenever I update vanilla I will need to check the new original file for changes and duplicate them into my tweaked file. Is there a better way to be doing this that is more modular? Also, where would I edit the default page title and description that are referenced in all.php

echo '<h1 class="H HomepageTitle">'.$this->Data('Title').'</h1>';
if ($Description = $this->Description()) {
   echo Wrap($Description, 'div', array('class' => 'P PageDescription'));
}

At the moment I have just commented these out and replaced them with static text like this..

echo '<h1 class="H HomepageTitle">Forums</h1>';

Thanks a lot

Alan

Best Answers

Answers

  • Options
    peregrineperegrine MVP
    edited September 2014

    I would avoid copying views like all.php - you will have a nightmare on your hands, during upgrades as you said and you also may not achieve the benefits of security fixes and new fireevent tirggers, etc, if it beocmes stale during the upgrade process.

    use a combo of plugin, themeoptions, or definitions, and or config settings. and pockets plugin and or messages from dashboard.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options

    Wow that is awesome, thanks. I don't know whether to be happy at how easy you made it or depressed that I wasted hours trying to do it the hard way :blush: If only I chosen the right search terms!

    That has got the page heading and description sorted, the only thing left now is to insert a heading above the categories list (since the original All Categories has been replaced by changing the HomepageTitle to Forums. As this is a whole new entry and not an edit of an existing item I assume it will be more complicated? Would I need to capture a rendering event and insert the heading as part of a function?

  • Options
    peregrineperegrine MVP
    edited September 2014

    post a screenshot and an arrow pointing to what you want to achieve.

    a picture is worth a thousand words

    pockets plugin or dashboard messages might do it for you. but I can't visualize what you want.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options

    Sorry for the delay, family life intervened :)

    Ignoring any formatting, in terms of content I want to take something like this...

    and change it into this

    I'll dig into the plugin you mention and see if I can use it to do what I need

    Thanks again for all your help

    Alan

  • Options

    I managed to do every thing I need with pockets and a few changes to CSS and default.master.tpl so thanks so much for the heads up!

  • Options

    At the moment I am inserting the HTML I need at the top of the All Categories page (which is my homepage) by defining the HTML in a pocket called "HomepageWelcome" and adding the following to my default.master.tpl

    {if InSection("CategoryList")}
    {pocket name="HomepageWelcome"}
    {/if}
    

    I was just wondering...is it possible to instead use a custom Smarty Function to return a HTML blob as I could just use something like this instead (and not have to run pockets)

    {if InSection("CategoryList")}
    {MyCustomSmartyWelcome}
    {/if}
    

    I started trying to create a function but wasn't sure how (or if it was even possible) to return the html text string I created as the functions I looked at all called a specific method to return the code (e.g. Breadcrumbs)

    return Gdn_Theme::Breadcrumbs($Breadcrumbs, FALSE);

    I can certainly get away with using pockets but I always tend to like to use the fewest plugins possible so if there is a simpler way...

    I did try to decipher the pockets plugin to see how it was doing things but it is a bit beyond my php/vanilla skills at the moment.

    Thanks

    Alan

  • Options

    Came up with this as a function, is it legit? It seems to work...

    function smarty_function_myforums_welcome($Params, &$Smarty) {
    
        $Welcome = '<div class="ForumWelcome">
                    <h1 class="H ForumWelcomeTitle">Forums</h1>
                    <div class="P ForumWelcomeText">
                        <P>Hello</P>
                    </div>
                </div>';
    
        echo T($Welcome);
    
        return;
    

    Thanks

    Alan

  • Options

    Ah much cleaner, thanks :)

  • Options

    Just moved the title and text into the definition file and now I think it is pretty good :)

Sign In or Register to comment.