开发者

PHP & HTML templating style preferences

开发者 https://www.devze.com 2023-01-25 22:14 出处:网络
Basically I have two ways for writing something First: <?php echo link_to( static_image_tag( $object->getImageWebPath(),

Basically I have two ways for writing something

First:

<?php
echo link_to(
  static_image_tag(
    $object->getImageWebPath(),
    array(
      "alt" => $object->getTitle(),
      "width" => "106",
      "height" => "73",
      "class" => 'aaa bbb'
     )
  ),
  url_for('route_name', $object),
  array(
    "class" => "aaa bbb", "title" => $object->getTitl开发者_开发百科e())
  );
?>

Second:

<a href="<?php echo url_for('route_name', $object->getLink()); ?>" title="<?php echo $object->getTitle(); ?>" class="aaa bbb">
  <img src="<?php echo map_to_static_domain($image->getWebPath()) . $image->getWebPath(); ?>" class="aaa bbb" alt="echo $image->getTitle()" "width" => "106", "height" => "73" />
</a>

Now the one 'million dollar question', which one way you guys use and maybe even why...

Thanks.


@Dave Vogt you need slapping Smarty is the biggest eye sore of code i have ever seen and it does some stuff so wrongly and uses so much memory its untrue,

Secondly it entirely depends on what your trying to do, if its a template engine your should use the first,

if its just for your web site then use the second


In my opinion, both are - humbly said - suboptimal.

I suggest you look into using a dedicated templating engine, such as Smarty.

I do like the programmatic approach, as (in theory) it could force you to produce valid (X)HTML code, but it's tedious to write, and interferes with the principle of separation between logic and presentation.

0

精彩评论

暂无评论...
验证码 换一张
取 消