1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Use stdClass in Templates

Discussion in 'XenForo Development Discussions' started by majafy, Aug 7, 2016.

  1. majafy

    majafy Member


    I have a stdClass variable which created in PHP, I use $template->create to pass it to my template.

    this is my template code :
    <xen:foreach loop="$datavalue="$i">
    But because $i is an object I get this error:
    Fatal error: Cannot use object of type stdClass as array in ...

    How Can I use stdClass in my templates?

  2. Chris D

    Chris D XenForo Developer Staff Member

    You can't unless it has array like behaviours such as implementing ArrayAccess or similar.

    Is this related to your JSON data from the other thread? If so, json_decode supports outputting an associative array rather than an object:

    $array json_decode($jsontrue);
  3. majafy

    majafy Member

    Thanks again Chris ;)

    Yes, This problem related to JSON question,
    I found this solution earlier, but I think there is a way to use object.
    anyway thank you for your help.

Share This Page