•  · 41 friends

Is UNA really limiting code inserts? No it isn't. Just read this ;)

What I observe here is a frequent complain "how to put code in our pages?!" "it is not possible!"

The method below is a super easy way to insert any code to your pages.

1. Create a raw block, position it where ever you like your code to appear in your UNA page. In that block only write a unique and strong place holder for instance *my?cod!e123*.

2. Go to page.php have a backup copy. replace these lines as described:

if ($oPage) {
$oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
$oTemplate->setPageType ($oPage->getType());
$oTemplate->setPageContent ('page_main_code', $oPage->getCode());
} else {

change to:

if ($oPage) {
$oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
$oTemplate->setPageType ($oPage->getType());
$oTemplate->setPageContent ('page_main_code', $oPage->getCode());}
else {
$currentpage = ob_get_clean();
now you have the html in your hand at $currentpage which is about to send to the browsers. Just replace your placeholder with your code, and echo the current page :) that's all.

$currentpage= str_replace ('*my?cod!e123*','ANY CODE',$currentpage);
echo $currentpage;

with this simple method you will open a big free area and use UNA's abilities with less restriction. Codes are from UNA 9.0, but there will not be so much change in the mechanism.

Advantages are:

Β you don't touch Una code and dont mix the page.

You can insert any code of yours

You may use the parameters like user id etc from Una functions as they are already loaded at the beginning of the page.

You may use the same block on different positions and pages.

Safety is measured by how safe your own code is.

Heading title padding background can be set by Una block settings

πŸ’“1 πŸ˜†0 😲0 πŸ˜₯0 😠0 0
  • 700
  • More
Replies (4)
    • Be careful with this code, if some user adds the text *mycode123* in any place(Discussion topic, Discussion text, Photo name, Album name, Their own name, etc), it will be replaced as well.

      If you really need this, you should add a really difficult combination instead of *mycode123*.

      Senior Developer.

      πŸ’“0 πŸ˜†0 😲0 πŸ˜₯0 😠0 0
      • Yes of course,Β  it should be "unique" andΒ  better a bit complex in real production environment :)

        πŸ’“0 πŸ˜†0 😲0 πŸ˜₯0 😠0 0
        • It's better to use service blocks instead. Service block can call any user's created code.Β 

          πŸ’“0 πŸ˜†0 😲0 πŸ˜₯0 😠0 0
          • I will check it Alex thank you.

            πŸ’“0 πŸ˜†0 😲0 πŸ˜₯0 😠0 0
            Not logged in users can't 'Comments Post'.

            UNA - Network Infrastructure for Communities