Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-38133

html_writer: add shortcuts for very frequent tags

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.4.1
    • 2.5
    • Libraries

    Description

      The html_writer class is generally convenient and safe but can result in rather long code. For example, if you want to add some accesshide text:

      echo html_writer::tag('span', $str, array('class' => 'accesside'));
      

      The problem is exacerbated when you are creating a structure of multiple tags.

      I propose creating shortcut methods for div and span, which are the most common structural tags. The shortcuts should also make it easier to add a CSS class as this is usually required for structural tags. This will allow for shorter code. (Other tags can continue to use the current methods.)

      Proposed code:

      echo html_writer::span($str, 'accesside');
      

      Attachments

        Issue Links

          Activity

            People

              quen Sam Marshall
              quen Sam Marshall
              Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Laurent David, Sara Arjona (@sarjona)
              Votes:
              3 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                14/May/13