(SOLVED) Plugin - General purpose text lines such as contact details, phone number, fax number, email address etc...

Post Reply
traxnamibia
Jr. Bludit
Posts: 4
Joined: Sun Sep 13, 2020 11:03 am

Hi there fellow Bludit users!

Please forgive me if the answer to my query is obvious or simple, but I am not at all familiar with PHP.

I am trying to create a simple plugin to store a bunch of variables such as phone number, fax number, email address etc.. and then pull those lines into a theme's PHP.

This is the code in plugin.php :

Code: Select all

<?php

class contactDetails extends Plugin {

    public function init()
    {
		$this->dbFields = array(
            'contactdetailstitle'=>'Company Name',
            'contactdetailsline1'=>'081 123 4567',
        );

        // make $contactDetails object available in theme
        global $contactDetails;
        $contactDetails = $this;
    }



	public function form()
	{
		global $L;
		
		$html  = '<div class="alert alert-primary" role="alert">';
		$html .= $this->description();
		
		$html .= '</div>';
		$html .= '<label>Contact Details Title:</label>';	
		$html .= '<input name="contactdetailstitle" id="jscontactdetailstitle" type="text" value="'.$this->getValue('contactdetailstitle').'">';	
		$html .= '<div>';
		
		$html .= '<label>Contact Details Line 1:</label>';
		$html .= '<input name="contactdetailsline1" id="jscontactdetailsline1" type="text" value="'.$this->getValue('contactdetailsline1').'">';	
		$html .= '</div>';

		return $html;
	}
		

	
   public function contactdetailstitle()
   {
		return $this->getValue('contactdetailstitle');
   }
		
	
    public function contactdetailsline1()
    {
		return $this->getValue('jscontactdetailsline1');
    }

}

?>
Image

and here is the code that I am using in my theme's PHP:

Code: Select all

<h2 class="footer-colour"><?php echo Theme::plugins('contactdetailstitle');?></h2>
	<ul>
			<li>
				   <span class="menu-item" style="color: #b9b8b7";><?php echo Theme::plugins('contactdetailsline1');?></span>
			</li>	
	</ul>
I am not sure whether the code issue lies within the plugin PHP or the theme PHP, but I simply cannot get the plugin data to display in my theme.

I would be very grateful if somebody could have a look at this code and perhaps enlighten me where the error lies?

Many thanks,

Bruce.
Last edited by traxnamibia on Mon Sep 14, 2020 3:51 pm, edited 1 time in total.
User avatar
Edi
Site Admin
Posts: 2084
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Contact:

traxnamibia wrote: Sun Sep 13, 2020 11:39 am

Code: Select all

[...]
	
   public function contactdetailstitle()
   {
		return $this->getValue('contactdetailstitle');
   }
		
	
    public function contactdetailsline1()
    {
		return $this->getValue('jscontactdetailsline1');
    }

[...]
Have you tried with echo instead of return?
Planet Bludit, Tipps, Snippets und nützliche Links. - Newsletter, Informationen zu Bludit (auf Deutsch).
traxnamibia
Jr. Bludit
Posts: 4
Joined: Sun Sep 13, 2020 11:03 am

Hi Edi,

Just tried echo, but still the same. Nothing displayed.
User avatar
Edi
Site Admin
Posts: 2084
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Contact:

I had a closer look at it.

Custom hooks cannot have fields:

https://docs.bludit.com/en/plugins/cust ... or-plugins

You can use a hook from the list in the documentation:

https://docs.bludit.com/en/plugins/hooks-list

The plugin can be inserted at any place in the theme with the following snippets:

https://docs.bludit.com/en/dev-snippets/plugins
Planet Bludit, Tipps, Snippets und nützliche Links. - Newsletter, Informationen zu Bludit (auf Deutsch).
traxnamibia
Jr. Bludit
Posts: 4
Joined: Sun Sep 13, 2020 11:03 am

Thanks Edi - I'll check it out in the morning.
I really appreciate the fact that the you took the time to look at it.
Bruce.
traxnamibia
Jr. Bludit
Posts: 4
Joined: Sun Sep 13, 2020 11:03 am

Edi - Many thanks for pointing me in the right direction.

I succeeded in creating the plugin I need by cloning your TEXTAREA plugin and making some minor changes.
Post Reply