Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Block Component

Block is a component helps developer separate a complex layout to varieties components in re-usage way.
Each block contains its own logic and template.

Create your first block

Create php class RecentItems under directory ./PF.Site/Apps/FirstApp/Block/

paste following codeAll phrases that used on your apps should be defined before using. The below instructions will help you:
How to to define?

Add a phrase.json file on under your app directory, this file contains all phrase in your app.

Example:

Code Block
php
php
<?php{ 
namespace Apps\TodoList\Block;  // RecentMembers block"Var mustName" be: child"", of
\Phpfox_Components // class RecentItems extends \Phpfox_Component
{

    // this method will be invoked by phpfox
    public function process()
    "var_name" : "Message Text"
}

There are 2 ways to define translation:

The easiest way

Put phrase on key, put blank on value (of json).

Example:

Code Block
php
php

{ 
     "Manage Video" : //"" assign
variables to template
        $this->template()
}

Use:

Code Block
php
php

<?php
echo _p("Manage Video");

// print Manage Video

var_name define:

Put var_name on key, put phrase on value (of json).

Example:

Code Block
php
php

{ 
     "manage_video" : "Manage Video" 
->assign([
                'sHeader' => 'Recent Items', // block title
                'aItems'  => ['Item 1', 'Item 2', 'Item 3'],
            ]);
        return 'block';
    }
}

Create php template file recent_items.html.php under directory ./PF.Site/Apps/FirstApp/Block/

...


<ul>
{foreach from=$aItems item=item}
<li class="category">
    <p>
        {$item}
    </p>
{/foreach}
</ul>

...

}

Usage

Code Block
php
php

<?php
echo _p("manage_video");

// print Manage Video
Code Block
php
php

<?php
_p('var_name', $attr);

Within phpFox template .html.php file:

Code Block
php
php

{_p var="var_name" $attr}

Within phpFox template *.html file:

Code Block
php
php

{{ _p("var_name", $arrt) }}

Within JavaScript file

Code Block
php
php
$module->addComponentNames('block', [
    'todo.recent_items' => Block\RecentItems::class,
]);

...

oTranslations['var_name', context]

Translate a phrase with context variables

Code Block
php
php

    protected function setComponent()
    {
        $this->component = [
            "block"      => [
                "recent_items"    => "",
            ],
            "controller" => [
                "index"   => "todo.index",
            ]
        ];
    }

    protected function setComponentBlock()
    {
        $this->component_block = [
            "Recent Items" => [
                "type_id"      => "0",
                "m_connection" => "todo.index",
                "component"    => "recent_items",
                "location"     => "3",
                "is_active"    => "1",
                "ordering"     => "1"
            ],
        ];
    }

Then update your app to apply your modification. Open browser again, see result:

Image Removed

"total_people_liked_this_blog" : "{total} people liked this blog
}

Usage

Code Block
php
php

<?php
echo _p("total_people_liked_this_blog", ["total" => 5]);

Result: 5 people liked this blog

Info

Use single sign { and } for variable.