Results 1 to 7 of 7

Thread: changing the length restriction of an alternate text

  1. #1
    New user
    Join Date
    06-03-10.
    Posts
    14

    Default changing the length restriction of an alternate text

    Hello

    When using an image as content element I would like to put some description in the alternate text line,which will show up when you click the image for a full view (mediabox). But the length of this description is limited. Can you change this, so I can put in more textlines?
    Does anyone has experience with this?

    Bert

  2. #2
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default Re: changing the length restriction of an alternate text

    Exercise caution with this. I think the ALT tag has a limit to the amount of characters because there's a certain point where Google thinks you are keyword stuffing.

    That said stuff these lines of code somewhere (the best place is /system/config/dcaconfig.php).

    Code:
    // This defaults to 255 so if you want to make longer...
    $GLOBALS['TL_DCA']['tl_content']['fields']['alt']['eval']['maxlength'] = 511;
    
    // If you want to make it multiline...
    $GLOBALS['TL_DCA']['tl_content']['fields']['alt']['inputType'] = 'textarea';
    
    // And without this the text area gets a bit long for your needs...
    $GLOBALS['TL_DCA']['tl_content']['fields']['alt']['eval']['style'] = 'height: 60px;';
    It's probably more "proper" to instead use the caption field. If you enter your text into that, you can copy the "ce_image.tpl" template from "/system/modules/frontend/templates/" into your theme's templates folder.

    Then you can customize it by changing...

    Code:
    <a href="<?php echo $this->href; ?>"<?php echo $this->attributes; ?> title="<?php echo $this->alt; ?>">
    to...

    Code:
    <a href="<?php echo $this->href; ?>"<?php echo $this->attributes; ?> title="<?php echo $this->caption; ?>">
    And if you don't want a caption below the actual image, remove this...

    Code:
    <?php if ($this->caption): ?>
    <div class="caption"><?php echo $this->caption; ?></div>
    <?php endif; ?>
    And that, in a nutshell, is an example of what rules about Contao...
    Brian

  3. #3
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: changing the length restriction of an alternate text

    Nice Tutorial

  4. #4
    New user
    Join Date
    06-03-10.
    Posts
    14

    Default Re: changing the length restriction of an alternate text

    I can put a longer text in the textarea, but when I save it still cuts of automatically at 255 characters?

    $GLOBALS['TL_DCA']['tl_content']['fields']['caption']['eval']['maxlength'] = 511;
    ?>

  5. #5
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default Re: changing the length restriction of an alternate text

    Oh... I bet it's the database (the column is set to 255).

    Still fixable, tiny bit more work.

    If someone else doesn't get to it first, I can show you how to fix that later (busy day at work today).
    Brian

  6. #6
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default Re: changing the length restriction of an alternate text

    Scrap all that -- you can put your code in a simple custom module folder...

    You'll need to create these 2 files. "z-custom-alt-tags" can be anything. The 'z' in front ensures it's loaded last (and isn't overridden by another module later on).

    1. /system/modules/z-custom-alt-tags/config/database.sql
    If you look in '/system/modules/backend/database.sql', you'll see the 'caption' field in the database is set to 255. So you're going to overwrite it here by putting this:

    Code:
    CREATE TABLE `tl_content` (
      `caption` varchar(511) NOT NULL default ''
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    2. /system/modules/z-custom-alt-tags/dca/tl_content.php
    You can put those 3 lines I gave you earlier in here instead.

    Code:
    $GLOBALS['TL_DCA']['tl_content']['fields']['caption']['eval']['maxlength'] = 511;
    $GLOBALS['TL_DCA']['tl_content']['fields']['caption']['inputType'] = 'textarea';
    $GLOBALS['TL_DCA']['tl_content']['fields']['caption']['eval']['style'] = 'height: 60px;';
    Then make those template changes if needed.

    So try that out. This is actually better because you have everything organized into one place.
    Brian

  7. #7
    New user
    Join Date
    06-03-10.
    Posts
    14

    Default Re: changing the length restriction of an alternate text

    Works perfect.
    First it didn't, but after I updated the database in the install tool, everything works fine.
    Thank you very much!
    Bert

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •