1

I'm using plugin Ad Wizard, supported custom fields.

Trying include additional asset field for html5 animated banners.

Here is dump array:

["groupId"]=>
  string(1) "1"
  ["assetId"]=>
  string(3) "144"
  ["url"]=>
  string(14) "http://localhost"
  ["startDate"]=>
  NULL
  ["endDate"]=>
  NULL
  ["maxViews"]=>
  string(1) "0"
  ["totalViews"]=>
  string(1) "2"
  ["totalClicks"]=>
  string(1) "0"
  ["filepath"]=>
  string(0) ""
  ["width"]=>
  int(0)
  ["height"]=>
  int(0)
  ["html"]=>
  string(0) ""
  ["revisionCreatorId":protected]=>
  NULL
  ["revisionNotes":protected]=>
  NULL
  ["_fieldsByHandle":"craft\base\Element":private]=>
  NULL
  ["_fieldParamNamePrefix":"craft\base\Element":private]=>
  NULL
  ["_normalizedFieldValues":"craft\base\Element":private]=>
  NULL
  ["_nextElement":"craft\base\Element":private]=>
  bool(false)
  ["_prevElement":"craft\base\Element":private]=>
  bool(false)
  ["_parent":"craft\base\Element":private]=>
  NULL
  ["_prevSibling":"craft\base\Element":private]=>
  NULL
  ["_nextSibling":"craft\base\Element":private]=>
  NULL
  ["_eagerLoadedElements":"craft\base\Element":private]=>
  NULL
  ["_currentRevision":"craft\base\Element":private]=>
  NULL
  ["_errors":"yii\base\Model":private]=>
  NULL
  ["_validators":"yii\base\Model":private]=>
  NULL
  ["_scenario":"yii\base\Model":private]=>
  string(7) "default"
  ["_events":"yii\base\Component":private]=>
  array(0) {
  }
  ["_eventWildcards":"yii\base\Component":private]=>
  array(0) {
  }
  ["_behaviors":"yii\base\Component":private]=>
  array(1) {
    ["customFields"]=>
    object(craft\behaviors\ContentBehavior)#545 (18) {
      ["bannerHtml"]=>
      NULL
      ["_customFieldValues":"craft\behaviors\ContentBehavior":private]=>
      array(0) {
      }
      ["owner"]=>
      *RECURSION*
    }
  }
  ["id"]=>
  string(3) "282"
  ["tempId"]=>
  NULL
  ["draftId"]=>
  NULL
  ["revisionId"]=>
  NULL
  ["uid"]=>
  string(36) "150f6150-28a2-4237-a2fc-bcd62751fc17"
  ["fieldLayoutId"]=>
  string(1) "7"
  ["structureId"]=>
  NULL
  ["contentId"]=>
  string(3) "382"
  ["enabled"]=>
  string(1) "1"
  ["archived"]=>
  string(1) "0"
  ["siteId"]=>
  string(1) "1"
  ["enabledForSite"]=>
  string(1) "1"
  ["title"]=>
  string(8) "Banner 1"
  ["slug"]=>
  NULL
  ["uri"]=>
  NULL
  ["dateCreated"]=>
  object(DateTime)#542 (3) {
    ["date"]=>
    string(26) "2019-10-08 16:36:46.000000"
    ["timezone_type"]=>
    int(3)
    ["timezone"]=>
    string(9) ""
  }
  ["dateUpdated"]=>
  object(DateTime)#544 (3) {
    ["date"]=>
    string(26) "2019-10-09 12:22:32.000000"
    ["timezone_type"]=>
    int(3)
    ["timezone"]=>
    string(9) ""
  }
  ["dateDeleted"]=>
  NULL
  ["root"]=>
  NULL
  ["lft"]=>
  NULL
  ["rgt"]=>
  NULL
  ["level"]=>
  NULL
  ["searchScore"]=>
  NULL
  ["trashed"]=>
  bool(false)
  ["awaitingFieldValues"]=>
  bool(false)
  ["propagating"]=>
  bool(false)
  ["propagateAll"]=>
  bool(false)
  ["newSiteIds"]=>
  array(0) {
  }
  ["resaving"]=>
  bool(false)
  ["duplicateOf"]=>
  NULL
  ["previewing"]=>
  bool(false)
  ["hardDelete"]=>
  bool(false)
}

bannerHtml value all time empty, trying with text field, its working fine, problem only in asset field.

UPD:

This solution works fine:

{% for ad in craft.adWizard.ads.group('TopBannerLeft').orderBy('RAND()').all() %}
    {% set asset = craft.assets().id(ad.assetId).one() %}
    {% if asset.extension == 'html' %}
        <iframe src="{{ asset.getUrl() }}" frameborder="0" vspace="0" hspace="0" width="390" height="80" marginwidth="0" marginheight="0" scrolling="no"></iframe>
    {% else %}
        {{ ad.displayAd() }}
    {% endif %}
{% endfor %}
  • Hi Elexer, I'm the author of the Ad Wizard plugin. Can you show us the Twig code? – Lindsey D Oct 9 at 23:04
  • Hi, updated with twig code, only this solution work for me, custom field with asset value given null any time. – Elexer Oct 11 at 7:22
  • Ok great! You should post your solution below as an Answer, then mark it as the "Accepted Answer". :) – Lindsey D Oct 14 at 20:11

Your Answer

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

Browse other questions tagged or ask your own question.