Echo html from am_page

Discussion in 'Customization & add-ons' started by awa_la, Aug 9, 2013.

Thread Status:
Not open for further replies.
  1. awa_la

    awa_la New Member

    Joined:
    May 8, 2009
    Messages:
    19
    Hello,

    I was looking for a way to add some text to the top of the 'Your Membership Information' page. Unless I'm mistaken, there is no place to do this in the dashboard area. So I was thinking that I could create a page in 'Pages' under 'Protected Content' and then echo that html at the top of main.phtml, before the links.

    I think I need to do something with "$this->getPageId()" and "$content", but I don't have the knowledge to put it together.

    If anyone can point me in the right direction (or spell it out for me!) I would appreciate it.

    Thanks,
    Scott
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    You can do it from site.php file (http://www.amember.com/docs/Site.php_file)

    Here is code to insert some html code on the top of the 'Your Membership Information' page:
    PHP:
    Am_Di::getInstance()->blocks->add(new Am_Block('member/main/top''My Block Title''my-block-id'null'renderMyBlock'));
     
    function 
    renderMyBlock() {
        
    $html = <<<CUT
        <p>You can put some html code here</p>
    CUT;
        return 
    $html;
    }
  3. awa_la

    awa_la New Member

    Joined:
    May 8, 2009
    Messages:
    19
    Thanks for the response Caesar. Currently, I have the html in a custom main.phtml file. However, I was looking for a way that other admins could easily change the text in the dashboard area, as they do not have access to the program files.

    Looking at ContentController.php,
    PHP:
    echo $p->html;
    is what outputs the text from an aMember page. Is there a way to get the content for page ID 2 and output that where I want?

    Thanks.
  4. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    @awa_la in this case I recommend you the following approach:

    1. create file html-config-form.php in folder where site.php file is located.
    2. put the following code in this file:
    Code:
    <?php
     
    class Am_Form_Setup_CustomHtml extends Am_Form_Setup
    {
        function __construct()
        {
            parent::__construct('custom-html');
            $this->setTitle(___('Custom HTML'));
        }
     
        function initElements()
        {
            $this->addHtmleditor('main_custom_html');
        }
    }
    3. add the followin code to site.php file (http://www.amember.com/docs/Site.php_file):
    HTML:
    //set up function to render block
    Am_Di::getInstance()->blocks->add(new Am_Block('member/main/top', 'My Block Title', 'my-block-id', null, 'renderMyBlock'));
     
    function renderMyBlock() {
        return Am_Di::getInstance()->config->get('main_custom_html');
    }
     
    //set up function to load our config form
    Am_Di::getInstance()->hook->add(Am_Event::SETUP_FORMS, 'siteGetSetupForms');
     
    function siteGetSetupForms(Am_Event_SetupForms $e)
    {
        include_once dirname(__FILE__) . '/html-config-form.php';
        $e->addForm(new Am_Form_Setup_CustomHtml('custom-html'));
    }
    That is all. In admin interface in section aMember CP -> Configuration -> Setup/Configuration you should see new tab now - 'Custom HTML'. You can put any html here and it will be shown on main page.

    All code related to this customization located in special files and do not affect core files. So you do not need to care about these changes in future during upgrade. Please let me know if it is suitable solution for you or not.
    awa_la likes this.
  5. awa_la

    awa_la New Member

    Joined:
    May 8, 2009
    Messages:
    19
    That's exactly what I needed. I think it will be less confusing than the approach I was taking.

    Thanks!
  6. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    You are welcome!
Thread Status:
Not open for further replies.

Share This Page