Content

What is Block Content?

The Content file (also known as render.php in WordPress) is the heart of your block – the actual markup and logic that determines what visitors see on your website when they view a page containing your block. This is where you define the HTML structure, dynamic content, and data output that gets rendered on the frontend.

Writing Your Block Content

You have complete flexibility in how you write your block’s content. FanCoolo supports both plain HTML and dynamic PHP, giving you the power to create anything from simple static blocks to complex, data-driven components.

Plain HTML

If your block doesn’t need any dynamic behavior, you can write standard HTML markup:

<div class="my-block">
    <h2>Welcome to My Block</h2>
    <p>This is a simple static block with hardcoded content.</p>
    <button class="btn">Click Me</button>
</div>

PHP with HTML

Mix PHP with HTML to create dynamic, customizable content:

<div class="my-block">
    <h2><?php echo esc_html($attributes['heading']); ?></h2>
    <p><?php echo esc_html($attributes['description']); ?></p>

    <?php if ($attributes['showButton']) : ?>
        <a href="<?php echo esc_url($attributes['buttonUrl']); ?>" class="btn">
            <?php echo esc_html($attributes['buttonText']); ?>
        </a>
    <?php endif; ?>
</div>

Using Block Attributes (Custom Fields)

Attributes are the custom fields you define in the Attributes Manager. They allow content editors to customize each instance of your block without touching code.

Accessing Attributes

All your block’s attributes are available through the $attributes array:

<div class="hero-section">
    <h1><?php echo esc_html($attributes['heading']); ?></h1>
    <p class="subtitle"><?php echo esc_html($attributes['subtitle']); ?></p>
</div>

Including Symbols

Symbols are reusable components like icons, logos, or repeated design elements that you can include in your blocks. This makes it easy to maintain consistent design elements across your site.

You include symbols using a self-closing tag syntax with the symbol name.

Basic Symbol Usage

<div class="card">
    <CompanyLogo />
    <h3><?php echo esc_html($attributes['title']); ?></h3>
    <p><?php echo esc_html($attributes['description']); ?></p>
</div>

Multiple Symbols

<div class="social-share">
    <h4>Share this post:</h4>
    <FacebookIcon />
    <TwitterIcon />
    <LinkedinIcon />
</div>

Conditional Symbols

<div class="status-indicator">
    <?php if ($attributes['status'] === 'success') : ?>
        <CheckIcon />
    <?php else : ?>
        <WarningIcon />
    <?php endif; ?>
    <span><?php echo esc_html($attributes['message']); ?></span>
</div>

Symbols in Loops

<div class="rating">
    <?php for ($i = 0; $i < intval($attributes['rating']); $i++) : ?>
        <StarIcon />
    <?php endfor; ?>
</div>

Built-in Error Prevention & Validation

FanCoolo includes intelligent error prevention to protect your site from broken code. This safety system ensures that only valid, working code makes it to your live site.

PHP Syntax Validation

Before generating your block’s render.php file, FanCoolo automatically validates that your PHP code is syntactically correct. This happens every time you save your block.

What gets validated:

  • PHP syntax errors (missing semicolons, unclosed brackets, etc.)
  • Invalid PHP tags
  • Function/variable naming issues
  • Parse errors

Safe File Generation

Only valid PHP code will be generated as a block file. If your code contains errors, the file generation process will be blocked and you’ll receive clear error messages.

Protection you get:

  • Prevents broken blocks from appearing in Gutenberg
  • Stops PHP fatal errors from reaching your live site
  • Ensures your blocks always work correctly
  • Protects your content editors from encountering errors

Clear Error Messages

When validation fails, you’ll receive helpful, actionable error messages that include:

Line Number: The exact line where the error occurred

Error on line 15: Unexpected token ')'

Error Type: What kind of error was detected

Parse Error: syntax error, unexpected ')', expecting ';'

Context: Information to help you understand and fix the problem

You may have a missing semicolon on the previous line, or an extra closing parenthesis.