Jump to content

[Blesta 3.2-3.5.1] How To Make Static Pages By Modifying Portal Plugin


Rodrigo

Recommended Posts

Hi,
 
I'm sharing a quick method for making custom static pages in blest system without any additional plugin. Please consider that any future update would require to take care of the changes made as they can be erased.
 
In this example I'll be doing a static page that will be located in your_blesta_location.com/services

 

1.1 Creating a static page with custom HTML
 
1. Open plugins/cms/controller/main.php
Find:

else {
  $this->redirect($this->base_uri);
}

Replace for:

else {
                        switch($uri) {
                          case 'services':
                            $this->structure->set("page_title", "*** INSERT PAGE TITLE ***");
                            $this->structure->set("title", "*** INSERT TITLE SHOWN ON PORTAL TEMPLATE ***");
                            // Placeholders won't work with this method, so let's use variables
                            $url = rtrim($this->base_url, "/");
                            $blesta_url = $this->Html->safe($url . WEBDIR);
                            $html = <<<EOT
 

    <div class="col-md-4 col-sm-6 portal-box">
        <a href="{$blesta_url}services>
            <div class="well">
                <i class="fa fa-cogs fa-4x"></i>
                <h4>Foo</h4>
                <p>Bar.</p>
            </div>
        </a>
    </div>

 
 
EOT;
                            $this->set("content", $html);
                            break;
                          default: 
                              $this->redirect($this->base_uri);
                        } 
}

You can repeat the php case for making all the static pages you want, putting HTML between the EOT marks (There should be no space or characters after EOT; mark). If you don't like the broken indentation you can try another methods for doing multi line strings in PHP, but I think using nowdoc is more easy when you need to insert html.

 

1.2 Adding custom meta tags to the new static page (optional)

 

1. Open plugins/cms/controller/main.php

Find

$this->set("content", $html);

Add Before:

                            $metatags = <<<EOT
<meta property="og:title" content="foo"/>
<meta property="og:description" content="bar."/>
<meta property="og:image" content="baz"/>
<meta property="og:url" content="http://www.example.com/services"/>
 
 
EOT;
                            $this->structure->set("metatags" , $metatags);

2. Open /app/views/client/bootstrap/structure.pdt (or in your own template)

Find

<meta name="viewport" content="width=device-width, initial-scale=1.0">

Add after

<?php echo $this->Html->ifSet($metatags) ?>

Dev note: this could be easier if could find a way to get structure protected property values, then concat the metatags to an existing variable like $custom_head (Is there a method like $this->structure->get()?)

 

 

 

Also, don't forget that the Portal plugin is being developed for being a fully functional CMS system, so this would not be needed in the future.

 

Here is my result, I'm linking this custom static page from the blesta portal main page for linking to different order pages (currently in design and module coding process, blesta flexibility is awesome)

 

Result:

 

1KeGrHc.png

 

Setting what Facebook shows by modifying meta tags

7xTTmHj.png

I hope somebody finds this useful

 

Bye

 

EDIT: fixed a detail in $url definition

EDIT2: Added how to add custom html into <head>

EDIT3. Confirming that this still works for Blesta 3.5.1

Edited by Rodrigo
Link to comment
Share on other sites

  • 6 months later...

Thank you, it's working fine!!

 

I was now thinking how some page could only be available for a given blesta's company?

 

I believe the company ID may be available, and a conditional could be created to display different content for different companies. I'll have to look into it, unless someone else knows?

Link to comment
Share on other sites

From Rodrigo hack, pages content are in plugins/cms/controller/main.php

 

but from my test & in the idea to port this hack for using it in Blesta multi companies,

 

  From my test, I think this variable "$system_company->id" seem to do not have  directly a value in such  "general" file  as not being in a view.

 

Maybe in plugins/cms/controller/main.php , $system_company->id variable it should be set before in this function:

 

      public function preAction() {

 

 

But I'm not enough skilled

Link to comment
Share on other sites

The solution for that work with multi-company is :
 


  else {  



       if ($this->company_id == "YOUR-COMPANY-ID")  {



                switch($uri)  {

                        case 'page-x':

                        SEE CONTENT HERE FROM ABOVE RODRIGO TUTORIAL


                       
                        case 'page-y':

                        SEE CONTENT HERE FROM ABOVE RODRIGO TUTORIAL


                }

         }



       if ($this->company_id == "YOUR-OTHER-COMPANY-ID")  {



             switch($uri)  {

                           case 'page-y1':

                           SEE CONTENT HERE FROM ABOVE RODRIGO TUTORIAL


                           case 'page-y2':

                           SEE CONTENT HERE FROM ABOVE RODRIGO TUTORIAL


              }

        }




 }



 

Link to comment
Share on other sites

Great Thank You!

 

Just tested, and working fine.

 

It's will be fine next version support these bellow custom, by page:

 

<title>XXXXXXX</title>

<meta name="Description" content="XXXXXXXXXXX">
<meta name="Geography" content="XXXXXXXX">
<meta name="country" content="XXXXXXXX">
<meta name="language" content="XXXXXXXXXXX">
<meta name="publisher" content="XXXXXXXXXXXXX">
<meta name="application-name" content="XXXXXXXXX">
<meta name="identifier-url" content="XXXXXXXXXX">


<meta property="og:title" content="XXXXXX" />
<meta property="og:description" content="XXXXXXXXX" />
<meta property="og:image" content="XXXXXXX" />
<meta property="og:url" content="XXXXXXXXX" />
 

Link to comment
Share on other sites

  • 2 weeks later...

There an issue in case of multi-companies, in one company non existing URL are not redirected to base_uri.

 

http://www.blesta.com/forums/index.php?/topic/4158-cms-plugin-multicompanies-missing-redirection-for-non-existing-url/

 

As the company that had this bug in my case was a one page company (and no more page used), I fixed it that way, by adding this just just before the closing of " else { "      at bottom, :

 

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

 

if ($this->company_id == "2")  {


//  REDIRECT TO BASE URI
  $this->redirect($this->base_uri);


 

 

 

}  // END of "else"

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

Link to comment
Share on other sites

  • 1 month later...

I think in structure.pdt you need to create condition .

 

In my case my homepage content comme from blesta portal plugin (edited from blesta interface) and I created condition in structure.pdt to display metatag depending if it's the display of homepage or a custom page, so you could take inspiration of this to apply on header display at basing your condition on the page tittle. and your custom page title will be definited in /plugins/cms/controllers/main.php

 

in structure.pdt:

                                <?php 
                                       if ($this->Html->ifSet($metatags)) {


                                                          // CASE :   NOT BEING HOMEPAGE

                                                                      //  PAGE TITLE COME FROM CMS 
                                                                      $title = (($page_title = (isset($page_title) ? $page_title : $this->_($page_title_lang, true, $get_params))) ? $this->Html->_($page_title, true) . " | " : "") . 'SiteShop . ph';

                                                                        echo "<title>".$title."</title>";

 
                                                                        //  METATAGS IN ADITION TO ABOVE 2 (viewport & Content-Type"), COME FROM CUSTOM STATIC PAGE ADDED IN:               /plugins/cms/controllers/main.php
                                                                        echo $this->Html->ifSet($metatags);

         


                                           
			                               }
			                          else {


                                                                       //  CASE:     HOMEPAGE,  add missing metatags
                                                                       $metatags = "


                                                                               <title>  xxxxxxxxxxxxxxxxxxxxxxx </title>
                                                                                

                                                                               <meta name=\"Description\" content=\"xxxxxxxxxxxxxxxx\">
                                                                               <meta name=\"Geography\" content=\"xxxxxxxxxxx\">
                                                                               <meta name=\"country\" content=\"xxxxxxxxxxx\">
                                                                               <meta name=\"language\" content=\"xxxxxxxxxxxxxx\">
                                                                               <meta name=\"publisher\" content=\"xxxxxxxxxxxxxxxxxx\">
                                                                               <meta name=\"application-name\" content=\"xxxxxxxxx\">
                                                                               <meta name=\"identifier-url\" content=\"http://xxxxxxxxxx\">
                                                                               

                                                                                <meta property=\"og:title\" content=\"xxxxxxxxxxxxxxxxxxxx" />
                                                                                <meta property=\"og:description\" content=\"xxxxxxxxxxxxxxx\" />
                                                                                <meta property=\"og:image\" content=\"xxxxxxxxxxxxxxxxx.png\" />
                                                                                <meta property=\"og:url\" content=\"http://xxxxxxxxxxxxxxx\" />



                                                                         ";
                                                                                      
                                                                
		                                
                                                          echo $metatags;

		                          
		                             }
		                   ?>
                       

in /plugins/cms/controllers/main.php  at the ending of your given custom page:

 

It's like above post, but it was missing common metatag VS only facebook metatag ("og: )

EOT;
                            $metatags = <<<EOT
<meta name="Description" content="xxxxxxxxx">
<meta name="Geography" content="vvvvvvvv">
<meta name="country" content="xxxxxxxxxxxx">
<meta name="language" content="xxxxxxxxxxxx">
<meta name="publisher" content="xxxxxxxxxxxxxxxxxxxx">
<meta name="application-name" content="xxxxxxxxxxxxxxxxx">

<meta property="og:title" content="Your Page Title" />
<meta property="og:description" content="xxxxxxxxxxxxxxxxx" />
<meta property="og:image" content="xxxxxxxxxxxxxxxxxxxxxxxxx" />
<meta property="og:url" content="{$blesta_url}xxxxxxxxxxxxxxxx" />
EOT;
                            $this->structure->set("metatags" , $metatags);
                            $this->set("content", $html);
                            break;
                        //  default: 
                              $this->redirect($this->base_uri);


Link to comment
Share on other sites

  • 4 weeks later...

I've installed admin tools and its a great tool. However in my case, I'm going to release themes for Blesta and not sure if this is the best solution for clients to install admin tool to use my theme. And if I don't use admin tools and make changes to main.php, I'm pretty sure client will mess up codes as well. Hope that blesta will implement a better custom static page on CMS soon.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...