3

So i've got this little plugin named AnnuaireAdherents with a variable that i try to access from within a template : annuaireadherents/ ├── AnnuaireAdherentsPlugin.php ├── services │   ├── AnnuaireAdherents_Service.php │   └── Proxy.php ├── twigextensions │   └── AnnuaireAdherentsTwigExtension.php └── variables └── AnnuaireAdherentsVariable.php

The variable should return a dynamic array, but let's try a static one first :

<?php namespace Craft;

/**
 * Variables provides access to list of adherents inside templates
 */
class AnnuaireAdherentsVariable {

    /**
     * Liste d'adhérents
     *
     * @return array
     */
    public function adherents() {
        return array(
            array(
                "raison_sociale" => "JOHN DOE & Co",
                "contact" => "JOHN DOE",
                "cp" => "99999",
                "address1" => "DESTINY STREET",
                "locality" => "NOWHERE",
                "mail" = "john.doe@nowhere.net"
            )
        );
    }
}

I've tried every namespace variants i could think of to access it inside a template :

{% for adh in craft.annuaireAdherents.adherents %}
    {{ adh.raison_sociale }}
{% endfor %}

but i keep receiving the error :

Method "annuaireAdherents" for object "Craft\CraftVariable" does not exist

Is it the correct namespace ? Do i have to relaunch Apache and Craft between each code modification to retest my variable ? Could there be another error that is masking me the true cause of this message ?

Thanks a lot for any clue / direction to investigate.

  • 3
    Sorry to ask, but did you install your plugin in Settings/Plugins? – carlcs Oct 12 '15 at 23:00
  • Don't be sorry to ask : it was the main cause ! I have to sync with the craft database updated by my coworker, and by doing that, i totally forgot that my plugin would be uninstalled as he doesn't have the plugin yet !! Thanks a lot for that silly one ! My apologies ! :) – zipang Oct 13 '15 at 7:43
3

Reinstalling the plugin after a database update just solved the problem : the database i sync'ed with didn't have the plugin installed (as it is still in development)

Sorry for that one... :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.