Question: In Magento 2 I've added a custom attribute to CMS pages (another post on here got me part of the way).

I used `UpgradeSchema.php` to create the new attribute and I can see my new attribute/column in the `cms_page` table. I also created an Observer to add the field to CMS pages in Admin, and the field works (changes are saved) in the `Admin > Content > Pages > Content` tab.

This is where I've got stuck. I've got this far by piecing together bits and pieces of information I could find, but I can't find anything on how to actually 'get' this data and output it on the frontend.

At the moment I have an (empty) Helper, and a `phtml` template which is ready to output the value in. But I don't know what to put in the Helper, or even if that is the right thing to do (should I be extending the Page or Block class from example)?

As a lowly frontend developer trying to muddle his way through a Magento world, I could do with a little nudge in the right direction. Thanks.

Answer: 
Based on Khoa's example above I was able to get things working.

Here's my Helper:

```
// app/code/VendorName/ModuleName/Helper/Data.php

namespace VendorName\ModuleName\Helper;

use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;

class Data extends AbstractHelper
{
  protected $_page;
  protected $_pageFactory;

  public function __construct(
    \Magento\Cms\Model\Page $page,
    \Magento\Cms\Model\PageFactory $pageFactory,
    Context $context,

    array $data = []
  )
  {
    $this->_page = $page;
    $this->_pageFactory = $pageFactory;
    parent::__construct($context, $data);
  }

  public function getCmsPageId() {
    return $this->_page->getId();
  }

  public function getMyCustomAttribute($id)
  {
    $page = $this->_pageFactory->create()->load($id);
    return $page->getData('my_custom_attribute');
  }
}

```

And then in my template:

```
$cmsPageId = $this->helper('VendorName\ModuleName\Helper\Data')->getCmsPageId();
$myCustomAttribute = $this->helper('VendorName\ModuleName\Helper\Data')->getMyCustomAttribute($cmsPageId);

```

This puts my custom attribute into the `$myCustomAttribute` variable, ready for me to do what I want with it.

I don't know if this is the best way to achieve what I want, but it works.
We should have a construction to inject `Magento\Cms\Api\PageRepositoryInterface`. For example, the helper likes:

**app/code/Vendor/Cms/Helper/Data.php**

```
namespace Vendor\Cms\Helper;

use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;

class Data extends AbstractHelper
{
    protected $pageRepository;

    public function __construct(
       \Magento\Cms\Api\PageRepositoryInterface $pageRepository,
        Context $context
    )
    {
        $this->pageRepository = $pageRepository;
        parent::__construct($context);
    }

    public function getCustomAttribute($id)
    {
        $page = $this->pageRepository->getById($id);
        return $page->getData('your_attribute');
    }
}

```