---
layout: docs
title: addIf
id: class.Facebook.HackCodegen.BaseCodeBuilder.addIf
docid: class.Facebook.HackCodegen.BaseCodeBuilder.addIf
permalink: /docs/reference/class.Facebook.HackCodegen.BaseCodeBuilder.addIf/
---
# Facebook\\HackCodegen\\BaseCodeBuilder::addIf()




If the condition is true, add code to the buffer; otherwise, do nothing




``` Hack
final public function addIf(
  bool $condition,
  string $code,
): this;
```




## Parameters




+ ` bool $condition `
+ ` string $code `




## Returns




* ` this `