sage-directives icon indicating copy to clipboard operation
sage-directives copied to clipboard

Add $format_value parameter for @field and @sub

Open vburlak opened this issue 4 years ago • 0 comments

Hey @Log1x. Thanks for one more awesome plugin, I appreciate all of your hard work!

I have an idea related to @field and @sub directives.

Original ACF the_field(), the_sub_field() allows optional $format_value param, which I found extra useful, when

  • you need to disable data formatting for specific field when it's not needed,
  • you want to avoid disabling acf_the_content filter for that field or all fields.

Issue with @field and @sub directives

Default ACF Example: I'm using the wysiwyg field and I could disable formatting on its value by passing false as a third param:

the_field('headline', false, false); // $selector, $post_id, $format_value

But sage-directives use different params logic within an additional feature, which helps to add an array key as a second parameter. (I found it very useful too!).

@field('headline', false, false); // $selector, $key, $post_id

Possible solution

The only solution I can see there to follow existing directive format — add expression to check for fourth/third expression here https://github.com/Log1x/sage-directives/blob/master/src/Directives/ACF.php#L50-L61

So the actual full param structure might be:

  • $selector (mixed)
  • $key (string)
  • $post_id (int)
  • $format_value (boolean)

The directive call to disable formatting might look like:

@field('headline', false, false, false);

I think my suggested solution not super clean and it needs a few extra tricks at logic to check all combinations within an additional $key param. But I would like to hear any of your thoughts/ideas on this?

P.S.: with the @sub — everything the same, but excluding $post_id param.

Thanks!

vburlak avatar Aug 16 '20 22:08 vburlak