Adding a new tempcode symbol...

Post

Posted
Rating:
#5221 (In Topic #1055)

how to do?

Hello,

I would like to add a new tempcode symbol sort of like the

Code

{$USER_AGENT}
that displays  "The user-agent string of the current user"

my idea is to create 

Code

{$BROWSERLANG}

so i can see what is the major language used by the current user.

I learned that the result of 
$_SERVER['HTTP_ACCEPT_LANGUAGE']
is not so straight forward, it may say the visitor as a few languages but will rank them...  I am looking at ideas about this issue:

http - Using the PHP HTTP_ACCEPT_LANGUAGE server variable - Stack Overflow

meanwhile to create my new tempcode symbol I read:

Code Book, part 1b (Further back-end concepts)

Open Source CMS with advanced social, interactive and dynamic features. Fully flexible, themeable and extendible: suitable for building powerful websites.

View


"...

Adding a new symbol, to refer to custom data and functions within templates

To add a new symbol you'll need to write a systems/symbols hook. This is a very useful technique for extending the Tempcode system...."

and

Code Book, part 1a (Core back-end programming)

Open Source CMS with advanced social, interactive and dynamic features. Fully flexible, themeable and extendible: suitable for building powerful websites.

View


 

Another example: symbols

Composr supports 'symbols' in templates, that do special things. An example of a symbol is our MEMBER_PROFILE_LINK symbol, which makes it easy to link to a member's profile screen from a template (often templates are passed member IDs as parameters, so it allows them to work with their parameters in an effective way). But Composr needs to be extendable. Addons must be able to add their own symbols (e.g. maybe an eCommerce addon would need to define a 'BALANCE' symbol to show a member's balance in any arbitrary template), so there are symbol hooks.

For performance Composr doesn't use any symbol hooks for any default functionality, but they are available for new addons.



so what I have done is create:
sources/hooks/systems/symbols/BROWSERLANG.php

Code

<?php 

class Hook_symbol_BROWSERLANG
{

    public function run($param)
    {
             $value = "test";
        return $value;
    }
}


note; I do not know what I am doing here, just copied a different one to see if I can get a result...:lol:

then in my page using the new tempcode i get this error:  A symbol is missing: BROWSERLANG........ 

thankyou in advance for any pointers on this.  I can figure out the $_SERVER['HTTP_ACCEPT_LANGUAGE'] stuff later but I am not sure how to create a new tempcode symbol...

:rockon:


 

Post

Posted
Rating:
#5222
I can't see anything wrong.

Try emptying the block cache. That as a by-product will flush the persistent cache, which contains a cache of all existent symbols. I suspect you've turned that cache on.

Post

Posted
Rating:
Item has a rating of 5 Item has a rating of 5 Item has a rating of 5 Item has a rating of 5 Item has a rating of 5 (Liked by Chris Graham)
#5224
:rockon:

It works! Super cool, excited to make many new tempcode symbols :)

Thank you

2 guests and 0 members have recently viewed this.