Bird
0
0

In Blade, how can you safely display a user's profile description that contains HTML tags without rendering the tags?

hard📝 Application Q8 of 15
Laravel - Views and Blade Templates
In Blade, how can you safely display a user's profile description that contains HTML tags without rendering the tags?
AUse PHP's <code>htmlspecialchars()</code> inside Blade
BUse <code>{!! $profile->description !!}</code> to render HTML
CUse <code>{{ $profile->description }}</code> to escape HTML
DUse <code>@raw($profile->description)</code> directive
Step-by-Step Solution
Solution:
  1. Step 1: Understand Blade escaping

    Using {{ }} escapes HTML tags, showing them as plain text.
  2. Step 2: Avoid raw output

    Using {!! !!} outputs raw HTML, which is unsafe if content is untrusted.
  3. Step 3: PHP functions are unnecessary

    Blade's escaping handles this automatically, so no need for htmlspecialchars().
  4. Final Answer:

    Use {{ $profile->description }} to escape HTML -> Option C
  5. Quick Check:

    Use {{ }} to escape HTML tags safely [OK]
Quick Trick: Use {{ }} to escape HTML tags in Blade [OK]
Common Mistakes:
  • Using {!! !!} which renders HTML unsafely
  • Manually escaping HTML instead of using Blade syntax
  • Assuming @raw directive exists in Blade

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes