We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin Newbie Question - tagdata

Development and Programming

Lee Powell's avatar
Lee Powell
88 posts
15 years ago
Lee Powell's avatar Lee Powell

Hi,

I’m trying to write a very basic plugin to format some text as such:

{exp:text_format:uppercase}Hello{/exp:text_format:uppercase}

I have created the plugin as per the user guide, and have the following method:

<?php

if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class Text_format
{
    
    var $return_data = '';
    
    
    function Text_format()
    {
        $this->EE =& get_instance();    
    }
    
    
    function uppercase()
    {
        $this->EE =& get_instance();
        $this->return_data = strtoupper($this->EE->TMPL->tagdata);
    }
    
    function lowercase()
    {
        $this->EE =& get_instance();
        $this->return_data = strtolower($this->EE->TMPL->tagdata);
    }
    
    function uppercase_first()
    {
        $this->EE =& get_instance();
        $this->return_data = ucfirst($this->EE->TMPL->tagdata);
    }
    
    function uppercase_words()
    {
        $this->EE =& get_instance();
        $this->return_data = ucwords($this->EE->TMPL->tagdata);
    }
        
    function usage()
    {
        
    }
        
}

But nothing gets returned. What am I doing wrong?

       
Lee Powell's avatar
Lee Powell
88 posts
15 years ago
Lee Powell's avatar Lee Powell

My bad - just noticed methods, other than the constructor can return directly.

This leads me onto another problem…

If I use a global variable like so:

{exp:text_format:uppercase}{a_global_var}{/exp:text_format:uppercase}

and return that, it breaks, as the plugin is simply upper casing the tag, rather than the content the tag returns…

Is there anyway around this?

       
Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
15 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team

The problem is the order in which EE tags are parsed. See: http://expressionengine.com/wiki/Parse_Order

See how late Global Variables are parsed?

       
Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
15 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team

An optional way around this would be to check to see if the var passed to the plugin is, in fact, a global variable and parse it yourself before uppercasing it. I’m not sure how necessary this is since you’re working with a demo plugin.

Do you have a specific need to manipulate global variables within a plugin?

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.