patternphpMinor
CakePHP view with interleaved PHP and HTML
Viewed 0 times
withphpviewcakephpinterleavedandhtml
Problem
It's CakePHP, though I'm more interested in what people think about the layout of the indentation, the mark-up, position of logic etc.
Any feedback that relates to the subject of writing CakePHP views / front end code should take precedence over CakePHP feedback or logic feedback, though the latters are welcome too
Any feedback that relates to the subject of writing CakePHP views / front end code should take precedence over CakePHP feedback or logic feedback, though the latters are welcome too
0): ?>
Html->link("Edit",$l['edit_route']) ?>
'>
display on home?
'>
Solution
Why not go with a template like Twig or Blade which would make the syntax a lot cleaner, while retaining most of all the controls. Also, remember that the view is for showing data, try to maintain as much logic OUT of the view as possible.
Here's an untested version of your code with Blade:
Here's an untested version of your code with Blade:
@foreach($list as $l)
@if($l['flag_count'] > 0)
{{ $l['flag_count'] }}
@else
{{ $l['flag_count'] }}
@endif
{{ $this->Html->link("Edit", $l['edit_route']) }}
{{ $l['translation']['english'][ $l['Content']['content_type'] . "_name" ] }}
@if($l['translation']['english'] != $current_language_id)
{{ $l['translation']['translate_to'][ $l['Content']['content_type'] . "_name" ] }}
@endif
@if('range' === $l['Content']['content_type'])
display on home?
@endif
@endforeach
Code Snippets
<ul class='content_list'>
@foreach($list as $l)
<li>
@if($l['flag_count'] > 0)
<span class='flag_count'>{{ $l['flag_count'] }}</span>
@else
<span class='zero_flags'>{{ $l['flag_count'] }}</span>
@endif
{{ $this->Html->link("Edit", $l['edit_route']) }}
<span class='english'>
{{ $l['translation']['english'][ $l['Content']['content_type'] . "_name" ] }}
</span>
@if($l['translation']['english'] != $current_language_id)
<span class='translate_to'>
{{ $l['translation']['translate_to'][ $l['Content']['content_type'] . "_name" ] }}
</span>
@endif
@if('range' === $l['Content']['content_type'])
<div class='js_slider_toggle' data-content-id='{{ $l['Content']['id'] }}'>
<span class='slider_label {{ $l['Content']['slider'] or "on_home" }}'>display on home?</span>
<span class='js_icon slider_toggle {{ $l['Content']['slider'] or "in_slider" }}'></span>
</div>
@endif
</li>
@endforeach
</ul>Context
StackExchange Code Review Q#59270, answer score: 2
Revisions (0)
No revisions yet.