Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Remove Title

edited April 2013 in Vanilla 2.0 - 2.8

Hi. I want to show the question itself, and not just the title on the main page. I also want to remove "title".

Heres is some examples:

Thanks for all help i can get!

Comments

  • KasperKasper Scholar of the Bits Copenhagen Vanilla Staff
    edited April 2013

    How about changing "Tittel" to "Sammendrag" instead? Or "Spørsmål" for that matter if it makes more sense.

    Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub

  • but that does not help if i want the users to see the actual question, not just a title.

  • KasperKasper Scholar of the Bits Copenhagen Vanilla Staff
    edited April 2013

    What it would do is encourage them to type in the actual question as the title

    Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub

  • That could work. But then i still got two boxes, and that is confusing for the visitors. It must be something i can change so that it displays the question and not the title, but i can't seem to find it.

  • businessdadbusinessdad Stealth contributor MVP

    Display Discussion body instead of Title

    Modify your theme to display the discussion body. In file vanilla/views/discussions/helper_functions.php, replace

    <?php echo Anchor($DiscussionName, $DiscussionUrl, 'Title'); ?>
    

    with

    <?php
      // TODO Improvement - Truncate Discussion body after a specific amount of characters
      $DiscussionBody = Gdn_Format::Text($Discussion->Body, false);
      echo Anchor($DiscussionBody, $DiscussionUrl, 'Title');
    ?>
    

    Remove Title field from the New Post form

    Title is a required field, it cannot be left empty. You can hide it using CSS, if you like, but you must then implement a handler for DiscussionModel::BeforeSaveDiscussion event to fill it before saving the Post.

    Example (untested)

    public function DiscussionModel_BeforeSaveDiscussion_Handler($Sender) {
      $FormPostValues = &$Sender->EventArguments['FormPostValues'];
    
      $FormPostValues['Name'] = 'Some value for the title';
    }
    

    Suggestion

    If you combine the two solutions, you can solve both problems in one shot, with less work. Here's what you could do.

    1- Hide the Discussion Title from the New Post with CSS
    2- Transform the Discussion Title into an excerpt of its body

    public function DiscussionModel_BeforeSaveDiscussion_Handler($Sender) {
      $FormPostValues = &$Sender->EventArguments['FormPostValues'];
    
      // Extract an excerpt of 50 characters from the Discussion body
      $DiscussionBodyExcerpt = substr(Gdn_Format::Text($FormPostValues['Body'], false), 0, 50);
      $FormPostValues['Name'] = $DiscussionBodyExcerpt;
    }
    

    This way, you do not need to change vanilla/views/discussions/helper_functions.php. The Discussion title will be displayed as usual, but it will contain a snippet of the body.

  • x00x00 MVP
    edited April 2013

    it is possible to do with a plugin or themehook. You would have to format the substituted title as Text only and truncate it.

    You could use DiscussionModel_BeforeSaveDiscussion_Handler

    You would change the Name field e.g. $Args['FormPostValues']['Name'] = SliceString(Gdn_Format::Text($Args['FormPostValues']['Body']),100);

    You could then hide the form field.

    That is pretty much all the help I can give you.

    grep is your friend.

  • Thank you so much businessdad! It now displays the body. Great! I think i can stick with the title after all.

Sign In or Register to comment.